Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Aashvitt authored Mar 5, 2024
1 parent d5585ae commit bea12f4
Show file tree
Hide file tree
Showing 14 changed files with 866 additions and 39 deletions.
39 changes: 39 additions & 0 deletions lib/BardAIController.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// ignore_for_file: file_names

import 'dart:convert';

import 'package:plant_sense_1/BardModel.dart';
import 'package:plant_sense_1/data.dart';
import 'package:get/get.dart';
import 'package:http/http.dart' as http;

class BardAIController extends GetxController {
RxList historyList = RxList<bardModel>([]);

RxBool isLoading = false.obs;
void sendPrompt(String prompt) async {
isLoading.value = true;
var newHistory = bardModel(system: "user", message: prompt);
historyList.add(newHistory);
final body = {
'prompt': {
'text': prompt,
},
};

final request = await http.post(
Uri.parse(
'https://generativelanguage.googleapis.com/v1beta2/models/text-bison-001:generateText?key=$APIKEY'),
headers: {
'Content-Type': 'application/json',
},
body: jsonEncode(body),
);

final response = jsonDecode(request.body);
final bardReplay = response["candidates"][0]["output"];
var newHistory2 = bardModel(system: "bard", message: bardReplay);
historyList.add(newHistory2);
isLoading.value = false;
}
}
24 changes: 24 additions & 0 deletions lib/BardModel.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// ignore_for_file: camel_case_types, no_leading_underscores_for_local_identifiers, file_names

class bardModel {
String? system;
String? message;

bardModel({this.system, this.message});

bardModel.fromJson(Map<String, dynamic> json) {
if (json["system"] is String) {
system = json["system"];
}
if (json["message"] is String) {
message = json["message"];
}
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> _data = <String, dynamic>{};
_data["system"] = system;
_data["message"] = message;
return _data;
}
}
22 changes: 22 additions & 0 deletions lib/biometric_helper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:local_auth/local_auth.dart';

class BiometricHelper {
final LocalAuthentication auth = LocalAuthentication();

Future<bool> hasEnrolledBiometrics() async {
final List<BiometricType> availableBiometrics =
await auth.getAvailableBiometrics();

if (availableBiometrics.isNotEmpty) {
return true;
}
return false;
}

Future<bool> authenticate() async {
final bool didAuthenticate = await auth.authenticate(
localizedReason: 'Authenticate to proceed',
options: const AuthenticationOptions(biometricOnly: false));
return didAuthenticate;
}
}
7 changes: 7 additions & 0 deletions lib/data.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// ignore_for_file: constant_identifier_names, non_constant_identifier_names
import 'package:flutter_dotenv/flutter_dotenv.dart';

String? APIKEY = dotenv.env['APIKEY'];
const String BaseURL =
"https://generativelanguage.googleapis.com/v1beta2/models/text-bison-001:generateText?key=YOUR_API_KEY";
String? MOISTURESENSOR = dotenv.env['MOISTURESENSOR'];
90 changes: 90 additions & 0 deletions lib/dictionary_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// ignore_for_file: must_be_immutable, use_build_context_synchronously

import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:plant_sense_1/dictionary_specie_disease.dart';

class Species extends StatelessWidget {
List<dynamic> arrTypes;
final String addr;
Species({
super.key,
required this.addr,
required this.arrTypes,
});

Future<List> getSpecies(String dis) async {
List<dynamic> ty = [];

Uri url = Uri.parse('${addr}api/dict/species/$dis');

final response = await http.get(url);
var jsonResponse = jsonDecode(response.body);
if (response.statusCode == 200) {
// If the server returns a 200 OK response, parse the JSON
ty = jsonResponse['Diseases'];
} else {
// If the server did not return a 200 OK response, throw an exception
throw Exception('Failed to load data');
}
return ty;
}

@override
Widget build(context) {
return Scaffold(
backgroundColor: const Color.fromARGB(255, 127, 60, 39),
appBar: AppBar(
title: Text(
"Species of Plants",
style: GoogleFonts.ebGaramond(
fontWeight: FontWeight.w300,
color: Colors.white,
fontSize: 25,
fontStyle: FontStyle.normal),
),
backgroundColor: Colors.green,
),
body: ListView.builder(
itemBuilder: (context, index) {
return Center(
child: Column(
children: [
const SizedBox(height: 50),
TextButton(
onPressed: () async {
List<dynamic> types = await getSpecies(arrTypes[index]);

Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SpeciesDisease(
species: arrTypes[index],
addr: addr,
arrTypes: types,
)),
);
},
style: FilledButton.styleFrom(
backgroundColor: Colors.green,
),
child: Text(
arrTypes[index],
style: GoogleFonts.ebGaramond(
fontWeight: FontWeight.w300,
color: Colors.white,
fontSize: 25,
fontStyle: FontStyle.normal,
),
),
),
],
),
);
},
itemCount: arrTypes.length,
));
}
}
92 changes: 92 additions & 0 deletions lib/dictionary_specie_disease.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// ignore_for_file: must_be_immutable, use_build_context_synchronously

import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:plant_sense_1/display_info.dart';

class SpeciesDisease extends StatelessWidget {
List<dynamic> arrTypes;
final String addr;
final String species;
SpeciesDisease({
super.key,
required this.addr,
required this.species,
required this.arrTypes,
});

Future<String> getInfo(String disease) async {
dynamic info;
disease = disease.replaceAll(RegExp(' +'), '_');
Uri url = Uri.parse('${addr}api/info/$disease');

final response = await http.get(url);
var jsonResponse = jsonDecode(response.body);
if (response.statusCode == 200) {
// If the server returns a 200 OK response, parse the JSON
info = jsonResponse['Information'];
} else {
// If the server did not return a 200 OK response, throw an exception
throw Exception('Failed to load data');
}
return info;
}

@override
Widget build(context) {
return Scaffold(
backgroundColor: const Color.fromARGB(255, 127, 60, 39),
appBar: AppBar(
title: Text(
"Species of Plants",
style: GoogleFonts.ebGaramond(
fontWeight: FontWeight.w300,
color: Colors.white,
fontSize: 25,
fontStyle: FontStyle.normal),
),
backgroundColor: Colors.green,
),
body: ListView.builder(
itemBuilder: (context, index) {
return Center(
child: Column(
children: [
const SizedBox(height: 50),
TextButton(
// onPressed: (){},
onPressed: () async {
String info = await getInfo(arrTypes[index]);

Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DiseaseInformation(
info: info,
disease: arrTypes[index],
)),
);
},
style: FilledButton.styleFrom(
backgroundColor: Colors.green,
),
child: Text(
arrTypes[index],
style: GoogleFonts.ebGaramond(
fontWeight: FontWeight.w300,
color: Colors.white,
fontSize: 25,
fontStyle: FontStyle.normal,
),
),
),
],
),
);
},
itemCount: arrTypes.length,
));
}
}
Loading

0 comments on commit bea12f4

Please sign in to comment.