1292 lines
43 KiB
Dart
1292 lines
43 KiB
Dart
import 'dart:convert';
|
||
import 'dart:io';
|
||
import 'package:SEFER/constant/box_name.dart';
|
||
import 'package:SEFER/constant/links.dart';
|
||
import 'package:SEFER/constant/style.dart';
|
||
import 'package:SEFER/controller/functions/crud.dart';
|
||
import 'package:SEFER/controller/functions/device_info.dart';
|
||
import 'package:SEFER/main.dart';
|
||
import 'package:SEFER/views/home/Captin/home_captain/home_captin.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'package:get/get.dart';
|
||
import 'package:image_cropper/image_cropper.dart';
|
||
import 'package:image_picker/image_picker.dart';
|
||
import 'package:http/http.dart' as http;
|
||
import 'package:image/image.dart' as img;
|
||
import 'package:path_provider/path_provider.dart';
|
||
|
||
import '../../constant/api_key.dart';
|
||
import '../../constant/colors.dart';
|
||
import 'tts.dart';
|
||
import 'upload_image.dart';
|
||
|
||
class AI extends GetxController {
|
||
bool approved = false;
|
||
bool isDriverSaved = false;
|
||
bool isCarSaved = false;
|
||
void setApproved() {
|
||
approved = true;
|
||
update();
|
||
}
|
||
|
||
final today = DateTime.now();
|
||
|
||
Future<void> addDriverAndCarEgypt() async {
|
||
final expiryDate = responseIdEgyptDriverLicense['expiry_date'];
|
||
final expiryDateTime = DateTime.tryParse(expiryDate);
|
||
final isExpired = expiryDateTime != null && expiryDateTime.isBefore(today);
|
||
|
||
final taxExpiryDate = responseIdCardDriverEgyptBack['tax_expiry'];
|
||
|
||
// Get the inspection date from the response
|
||
final inspectionDate = responseIdCardDriverEgyptBack['inspection_date'];
|
||
final year = int.parse(inspectionDate.split('-')[0]);
|
||
// Try parsing the tax expiry date. If it fails, set it to null.
|
||
final taxExpiryDateTime = DateTime.tryParse(taxExpiryDate ?? '');
|
||
final isExpiredCar =
|
||
taxExpiryDateTime != null && taxExpiryDateTime.isBefore(today);
|
||
|
||
// Check if the inspection date is before today
|
||
final inspectionDateTime = DateTime(year, 1, 1);
|
||
final isInspectionExpired = inspectionDateTime.isBefore(today);
|
||
|
||
if (isExpiredCar || isInspectionExpired) {
|
||
Get.defaultDialog(
|
||
title: 'Expired Driver’s License'.tr,
|
||
content: Column(
|
||
mainAxisSize: MainAxisSize.min,
|
||
children: [
|
||
const Icon(Icons.warning, size: 48, color: Colors.red),
|
||
const SizedBox(height: 16),
|
||
Text(
|
||
'Your driver’s license and/or car tax has expired. Please renew them before proceeding.'
|
||
.tr,
|
||
textAlign: TextAlign.center,
|
||
style: AppStyle.title,
|
||
),
|
||
const SizedBox(height: 16),
|
||
IconButton(
|
||
onPressed: () async {
|
||
await Get.find<TextToSpeechController>().speakText(
|
||
'Your driver’s license and/or car tax has expired. Please renew them before proceeding.'
|
||
.tr,
|
||
);
|
||
},
|
||
icon: const Icon(Icons.volume_up),
|
||
),
|
||
],
|
||
),
|
||
actions: [
|
||
TextButton(
|
||
onPressed: () {
|
||
Get.back();
|
||
},
|
||
child: const Text('OK'),
|
||
),
|
||
],
|
||
);
|
||
} else if (isExpired) {
|
||
Get.defaultDialog(
|
||
title: 'Expired Driver’s License'.tr,
|
||
content: Column(
|
||
mainAxisSize: MainAxisSize.min,
|
||
children: [
|
||
const Icon(Icons.warning, size: 48, color: Colors.red),
|
||
const SizedBox(height: 16),
|
||
Text(
|
||
'Your driver’s license has expired. Please renew it before proceeding.'
|
||
.tr,
|
||
textAlign: TextAlign.center,
|
||
style: AppStyle.title,
|
||
),
|
||
const SizedBox(height: 16),
|
||
IconButton(
|
||
onPressed: () async {
|
||
await Get.find<TextToSpeechController>().speakText(
|
||
'Your driver’s license has expired. Please renew it before proceeding.'
|
||
.tr,
|
||
);
|
||
},
|
||
icon: const Icon(Icons.volume_up),
|
||
),
|
||
],
|
||
),
|
||
actions: [
|
||
TextButton(
|
||
onPressed: () {
|
||
Get.back();
|
||
},
|
||
child: const Text('OK'),
|
||
),
|
||
],
|
||
);
|
||
} else if (responseIdEgyptDriverLicense['national_number'] !=
|
||
responseIdEgyptBack['nationalID']) {
|
||
Get.defaultDialog(
|
||
barrierDismissible: false,
|
||
title: 'ID Mismatch',
|
||
content: Column(
|
||
mainAxisSize: MainAxisSize.min,
|
||
children: [
|
||
const Icon(Icons.warning, size: 48, color: Colors.red),
|
||
const SizedBox(height: 16),
|
||
Text(
|
||
'The national number on your driver’s license does not match the one on your ID document. Please verify and provide the correct documents.'
|
||
.tr,
|
||
textAlign: TextAlign.center,
|
||
style: AppStyle.title,
|
||
),
|
||
const SizedBox(height: 16),
|
||
IconButton(
|
||
onPressed: () async {
|
||
await Get.find<TextToSpeechController>().speakText(
|
||
'The national number on your driver’s license does not match the one on your ID document. Please verify and provide the correct documents.',
|
||
);
|
||
},
|
||
icon: const Icon(Icons.volume_up),
|
||
),
|
||
],
|
||
),
|
||
actions: [
|
||
TextButton(
|
||
onPressed: () {
|
||
Get.back();
|
||
},
|
||
child: const Text('OK'),
|
||
),
|
||
],
|
||
);
|
||
}
|
||
// else if (responseCriminalRecordEgypt['FullName'] !=
|
||
// responseIdEgyptDriverLicense['name_arabic']) {
|
||
// Get.defaultDialog(
|
||
// barrierDismissible: false,
|
||
// title: 'Criminal Record Mismatch',
|
||
// content: Column(
|
||
// mainAxisSize: MainAxisSize.min,
|
||
// children: [
|
||
// const Icon(Icons.warning, size: 48, color: Colors.red),
|
||
// const SizedBox(height: 16),
|
||
// Text(
|
||
// 'The full name on your criminal record does not match the one on your driver’s license. Please verify and provide the correct documents.'
|
||
// .tr,
|
||
// textAlign: TextAlign.center,
|
||
// style: AppStyle.title,
|
||
// ),
|
||
// const SizedBox(height: 16),
|
||
// IconButton(
|
||
// onPressed: () async {
|
||
// await Get.find<TextToSpeechController>().speakText(
|
||
// 'The full name on your criminal record does not match the one on your driver’s license. Please verify and provide the correct documents.'
|
||
// .tr,
|
||
// );
|
||
// },
|
||
// icon: const Icon(Icons.volume_up),
|
||
// ),
|
||
// ],
|
||
// ),
|
||
// actions: [
|
||
// TextButton(
|
||
// onPressed: () {
|
||
// Get.back();
|
||
// },
|
||
// child: const Text('OK'),
|
||
// ),
|
||
// ],
|
||
// );
|
||
// }
|
||
else {
|
||
await addDriverEgypt();
|
||
await addRegistrationCarEgypt();
|
||
|
||
if (isCarSaved && isDriverSaved) {
|
||
DeviceController().getDeviceSerialNumber();
|
||
box.write(BoxName.phoneVerified, '1');
|
||
Get.offAll(() => HomeCaptain());
|
||
// Get.offAll(() => HomeCaptain());
|
||
}
|
||
}
|
||
}
|
||
|
||
Future<void> addDriverEgypt() async {
|
||
isLoading = true;
|
||
update();
|
||
|
||
var payload = {
|
||
'first_name': responseIdEgyptDriverLicense['firstName']?.toString() ??
|
||
'Not specified',
|
||
'last_name': responseIdEgyptDriverLicense['lastName']?.toString() ??
|
||
'Not specified',
|
||
'email': box.read(BoxName.emailDriver)?.toString() ?? 'Not specified',
|
||
'phone': box.read(BoxName.phoneDriver)?.toString() ?? 'Not specified',
|
||
'id': box.read(BoxName.driverID)?.toString() ?? 'Not specified',
|
||
'password': '123456',
|
||
'gender': responseIdEgyptBack['gender']?.toString() ?? 'Not specified',
|
||
'license_type':
|
||
responseIdEgyptDriverLicense['license_type']?.toString() ??
|
||
'Not specified',
|
||
'national_number':
|
||
responseIdEgyptBack['nationalID']?.toString() ?? 'Not specified',
|
||
'name_arabic': responseIdEgyptDriverLicense['name_arabic']?.toString() ??
|
||
'Not specified',
|
||
'name_english':
|
||
responseIdEgyptDriverLicense['name_english']?.toString() ??
|
||
'Not specified',
|
||
'issue_date': responseIdEgyptDriverLicense['issue_date']?.toString() ??
|
||
'Not specified',
|
||
'expiry_date': responseIdEgyptDriverLicense['expiry_date']?.toString() ??
|
||
'Not specified',
|
||
'license_categories': responseIdEgyptDriverLicense['license_categories']
|
||
is List
|
||
? responseIdEgyptDriverLicense['license_categories'].join(', ')
|
||
: responseIdEgyptDriverLicense['license_categories']?.toString() ??
|
||
'Not specified',
|
||
'address': responseIdEgyptFront['address']?.toString() ?? 'Not specified',
|
||
'card_id': responseIdEgyptFront['card_id']?.toString() ?? 'Not specified',
|
||
'occupation':
|
||
responseIdEgyptBack['occupation']?.toString() ?? 'Not specified',
|
||
'education':
|
||
responseIdEgyptBack['occupation']?.toString() ?? 'Not specified',
|
||
'licenseIssueDate':
|
||
responseIdEgyptDriverLicense['issue_date']?.toString() ??
|
||
'Not specified',
|
||
'religion':
|
||
responseIdEgyptBack['religion']?.toString() ?? 'Not specified',
|
||
'status': 'yet',
|
||
'birthdate': responseIdEgyptFront['dob']?.toString() ?? 'Not specified',
|
||
'maritalStatus':
|
||
responseIdEgyptBack['maritalStatus']?.toString() ?? 'Not specified',
|
||
'site': responseIdEgyptDriverLicense['address']?.toString() ??
|
||
'Not specified',
|
||
'employmentType':
|
||
responseIdEgyptDriverLicense['employmentType']?.toString() ??
|
||
'Not specified',
|
||
};
|
||
var res = await CRUD().post(link: AppLink.signUpCaptin, payload: payload);
|
||
var status1 = jsonDecode(res);
|
||
isLoading = false;
|
||
update();
|
||
print(res);
|
||
// Handle response
|
||
if (status1['status'] == 'success') {
|
||
isDriverSaved = true;
|
||
Get.snackbar('Success', 'Driver data saved successfully',
|
||
backgroundColor: AppColor.greenColor);
|
||
} else {
|
||
Get.snackbar('Error', 'Failed to save driver data',
|
||
backgroundColor: Colors.red);
|
||
}
|
||
// } catch (e) {
|
||
// isLoading = false;
|
||
// update();
|
||
// Get.snackbar('Error', 'An error occurred while saving driver data: $e',
|
||
// backgroundColor: Colors.red);
|
||
// }
|
||
}
|
||
// Future<void> addDriverEgypt() async {
|
||
// // try {
|
||
// // Extract values from box or set defaults
|
||
// var firstName = responseIdEgyptDriverLicense['firstName'] ?? '';
|
||
// var lastName = responseIdEgyptDriverLicense['lastName'] ?? '';
|
||
// var email = box.read(BoxName.emailDriver) ?? '';
|
||
// var phone = box.read(BoxName.phoneDriver)?.toString() ?? '';
|
||
// var driverId = box.read(BoxName.driverID)?.toString() ?? '';
|
||
// var password = '123456';
|
||
// var gender = responseIdEgyptBack['gender'] == 'ذكر' ? 'Male' : 'Female';
|
||
// var licenseType = responseIdEgyptDriverLicense['license_type'] ?? '';
|
||
// var nationalNumber = responseIdEgyptBack['nationalID'] ?? '';
|
||
// var nameArabic = responseIdEgyptDriverLicense['name_arabic'] ?? '';
|
||
// var nameEnglish = responseIdEgyptDriverLicense['name_english'] ?? '';
|
||
// var issueDate = responseIdEgyptDriverLicense['issue_date'] ?? '';
|
||
// var expiryDate = responseIdEgyptDriverLicense['expiry_date'] ?? '';
|
||
// var licenseCategories =
|
||
// responseIdEgyptDriverLicense['license_categories'] ?? '';
|
||
// var address = responseIdEgyptFront['address'] ?? '';
|
||
// var cardId = responseIdEgyptFront['card_id'] ?? '';
|
||
// var occupation = responseIdEgyptBack['occupation'] ?? '';
|
||
// var education = responseIdEgyptBack['occupation'] ?? '';
|
||
// var licenseIssueDate =
|
||
// responseIdEgyptDriverLicense['issue_date'].toString() ?? '';
|
||
// var religion = responseIdEgyptBack['religion'] ?? '';
|
||
// var status = responseIdEgyptBack['fullName'] ?? '';
|
||
// var birthdate = responseIdEgyptFront['dob'] != null
|
||
// ? DateTime.parse(responseIdEgyptFront['dob'] + '-01-01').toString()
|
||
// : '1960-01-01';
|
||
//
|
||
// var maritalStatus = responseIdEgyptBack['maritalStatus'] ?? '';
|
||
// var site = responseIdEgyptDriverLicense['address'] ?? '';
|
||
// var employmentType = responseIdEgyptDriverLicense['employmentType'] ?? '';
|
||
//
|
||
// // Create payload
|
||
// var payload = {
|
||
// 'first_name': firstName,
|
||
// 'last_name': lastName,
|
||
// 'email': email,
|
||
// 'phone': phone,
|
||
// 'id': driverId,
|
||
// 'password': password,
|
||
// 'gender': gender,
|
||
// 'license_type': licenseType,
|
||
// 'national_number': nationalNumber,
|
||
// 'name_arabic': nameArabic,
|
||
// 'name_english': nameEnglish,
|
||
// 'issue_date': issueDate,
|
||
// 'expiry_date': expiryDate,
|
||
// 'license_categories': licenseCategories,
|
||
// 'address': address,
|
||
// 'card_id': cardId,
|
||
// 'occupation': occupation,
|
||
// 'education': education,
|
||
// 'licenseIssueDate': licenseIssueDate,
|
||
// 'religion': religion,
|
||
// 'status': status,
|
||
// 'birthdate': birthdate,
|
||
// 'maritalStatus': maritalStatus,
|
||
// 'site': site,
|
||
// 'employmentType': employmentType,
|
||
// };
|
||
// isLoading = true;
|
||
// update();
|
||
// // Make POST request
|
||
// var res = await CRUD().post(link: AppLink.signUpCaptin, payload: payload);
|
||
// var status1 = jsonDecode(res);
|
||
// isLoading = false;
|
||
// update();
|
||
// // Handle response
|
||
//
|
||
// if (status1['status'] == 'success') {
|
||
// isDriverSaved = true;
|
||
// Get.snackbar('Success', 'Driver data saved successfully',
|
||
// backgroundColor: AppColor.greenColor);
|
||
// } else {
|
||
// Get.snackbar('Error', 'Failed to save driver data',
|
||
// backgroundColor: Colors.red);
|
||
// }
|
||
// // } catch (e) {
|
||
// // Get.snackbar('Error', 'An error occurred while saving driver data',
|
||
// // backgroundColor: Colors.red);
|
||
// // }
|
||
// }
|
||
|
||
Future addRegistrationCarEgypt() async {
|
||
try {
|
||
isLoading = true;
|
||
update();
|
||
var res = await CRUD().post(link: AppLink.addRegisrationCar, payload: {
|
||
'driverID': box.read(BoxName.driverID),
|
||
'vin': responseIdCardDriverEgyptBack['chassis'].toString(),
|
||
'car_plate': responseIdCardDriverEgyptFront['car_plate'].toString(),
|
||
'make': responseIdCardDriverEgyptBack['make'].toString(),
|
||
'model': responseIdCardDriverEgyptBack['model'],
|
||
'year': responseIdCardDriverEgyptBack['year'].toString(),
|
||
'expiration_date':
|
||
responseIdCardDriverEgyptFront['LicenseExpirationDate'].toString(),
|
||
'color': responseIdCardDriverEgyptBack['color'],
|
||
'owner': responseIdCardDriverEgyptFront['owner'],
|
||
'color_hex': responseIdCardDriverEgyptBack['color_hex'].toString(),
|
||
'address': responseIdCardDriverEgyptFront['address'].toString(),
|
||
'displacement': responseIdCardDriverEgyptBack['engine'].toString(),
|
||
'fuel': responseIdCardDriverEgyptBack['fuel'].toString(),
|
||
'registration_date':
|
||
'${responseIdCardDriverEgyptBack['inspection_date']}',
|
||
});
|
||
isLoading = false;
|
||
update();
|
||
var status = jsonDecode(res);
|
||
if (status['status'] == 'success') {
|
||
isCarSaved = true;
|
||
Get.snackbar('Success', 'message',
|
||
backgroundColor: AppColor.greenColor);
|
||
}
|
||
} catch (e) {}
|
||
}
|
||
|
||
final picker = ImagePicker();
|
||
Map<String, dynamic> responseMap = {};
|
||
Map<String, dynamic> responseCarLicenseMapJordan = {};
|
||
Map<String, dynamic> responseBackCarLicenseMap = {};
|
||
Map<String, dynamic> responseIdCardMap = {};
|
||
Map<String, dynamic> responseIdCardDriverEgyptBack = {};
|
||
Map<String, dynamic> responseIdCardDriverEgyptFront = {};
|
||
Map<String, dynamic> responseIdEgyptFront = {};
|
||
Map<String, dynamic> responseCriminalRecordEgypt = {};
|
||
Map<String, dynamic> responseIdEgyptBack = {};
|
||
Map<String, dynamic> responseIdEgyptDriverLicense = {};
|
||
String? responseIdCardDriverEgypt1;
|
||
bool isloading = false;
|
||
var image;
|
||
CroppedFile? croppedFile;
|
||
DateTime now = DateTime.now();
|
||
Future<void> pickImage() async {
|
||
final pickedImage = await picker.pickImage(source: ImageSource.gallery);
|
||
|
||
if (pickedImage != null) {
|
||
image = File(pickedImage.path);
|
||
// Crop the image
|
||
croppedFile = await ImageCropper().cropImage(
|
||
sourcePath: image!.path,
|
||
aspectRatioPresets: [
|
||
CropAspectRatioPreset.square,
|
||
CropAspectRatioPreset.ratio3x2,
|
||
CropAspectRatioPreset.original,
|
||
CropAspectRatioPreset.ratio4x3,
|
||
CropAspectRatioPreset.ratio16x9
|
||
],
|
||
uiSettings: [
|
||
AndroidUiSettings(
|
||
toolbarTitle: 'Cropper'.tr,
|
||
toolbarColor: AppColor.blueColor,
|
||
toolbarWidgetColor: AppColor.yellowColor,
|
||
initAspectRatio: CropAspectRatioPreset.original,
|
||
lockAspectRatio: false),
|
||
IOSUiSettings(
|
||
title: 'Cropper'.tr,
|
||
),
|
||
],
|
||
);
|
||
// image = croppedFile;
|
||
|
||
// Resize the image
|
||
final rawImage =
|
||
img.decodeImage(File(croppedFile!.path).readAsBytesSync());
|
||
final resizedImage =
|
||
img.copyResize(rawImage!, width: 800); // Adjust the width as needed
|
||
|
||
final appDir = await getTemporaryDirectory();
|
||
final resizedImagePath = '${appDir.path}/resized_image.jpg';
|
||
|
||
final resizedImageFile = File(resizedImagePath);
|
||
resizedImageFile.writeAsBytesSync(
|
||
img.encodeJpg(resizedImage)); // Save the resized image as JPEG
|
||
|
||
image = resizedImageFile;
|
||
update();
|
||
}
|
||
}
|
||
|
||
bool isLoading = false;
|
||
Future allMethodForAI(String prompt, linkPHP, imagePath) async {
|
||
isLoading = true;
|
||
update();
|
||
await ImageController().choosImage(linkPHP, imagePath);
|
||
Future.delayed(const Duration(seconds: 2));
|
||
// print(imagePath);
|
||
var extractedString =
|
||
await CRUD().arabicTextExtractByVisionAndAI(imagePath: imagePath);
|
||
print(extractedString);
|
||
var json = jsonDecode(extractedString);
|
||
var textValues = CRUD().extractTextFromLines(json);
|
||
print(textValues);
|
||
// await Get.put(AI()).geminiAiExtraction(prompt, textValues, imagePath);
|
||
await Get.put(AI()).anthropicAI(textValues, prompt, imagePath);
|
||
isLoading = false;
|
||
update();
|
||
}
|
||
|
||
Future<void> generateContent() async {
|
||
await pickImage();
|
||
if (image != null) {
|
||
final imageBytes = await image.readAsBytes();
|
||
final imageData = base64Encode(imageBytes);
|
||
|
||
var requestBody = jsonEncode({
|
||
'contents': [
|
||
{
|
||
'parts': [
|
||
{
|
||
'inlineData': {
|
||
'mimeType': 'image/jpeg',
|
||
'data': imageData,
|
||
},
|
||
},
|
||
{
|
||
'text':
|
||
'write json for all data as first name ,last name,dob,licenseID,expiration date,issued date asdress class type ,output json type',
|
||
},
|
||
],
|
||
},
|
||
],
|
||
'generationConfig': {
|
||
'temperature': 0.4,
|
||
'topK': 32,
|
||
'topP': 1,
|
||
'maxOutputTokens': 4096,
|
||
'stopSequences': [],
|
||
},
|
||
'safetySettings': [
|
||
{
|
||
'category': 'HARM_CATEGORY_HARASSMENT',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
{
|
||
'category': 'HARM_CATEGORY_HATE_SPEECH',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
{
|
||
'category': 'HARM_CATEGORY_SEXUALLY_EXPLICIT',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
{
|
||
'category': 'HARM_CATEGORY_DANGEROUS_CONTENT',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
],
|
||
});
|
||
|
||
final response = await http.post(
|
||
Uri.parse(
|
||
'https://generativelanguage.googleapis.com/v1beta/models/gemini-pro-vision:generateContent?key=${AK.geminiApi}'),
|
||
headers: {'Content-Type': 'application/json'},
|
||
body: requestBody,
|
||
);
|
||
|
||
if (response.statusCode == 200) {
|
||
var responseData = jsonDecode(response.body);
|
||
// Process the responseData as needed
|
||
|
||
var result =
|
||
responseData['candidates'][0]['content']['parts'][0]['text'];
|
||
RegExp regex = RegExp(r"```json([^`]*)```");
|
||
String? jsonString =
|
||
regex.firstMatch(responseData.toString())?.group(1)?.trim();
|
||
|
||
if (jsonString != null) {
|
||
// Convert the JSON object to a String
|
||
jsonString = jsonEncode(json.decode(jsonString));
|
||
} else {}
|
||
|
||
// Rest of your code...
|
||
} else {}
|
||
} else {}
|
||
}
|
||
|
||
Future<dynamic> anthropicAI(
|
||
String payload, String prompt, String idType) async {
|
||
var messagesData = [
|
||
{
|
||
"role": "user",
|
||
"content": [
|
||
{"type": "text", "text": "$payload $prompt"}
|
||
]
|
||
}
|
||
];
|
||
|
||
var requestBody = jsonEncode({
|
||
"model": "claude-3-haiku-20240307",
|
||
"max_tokens": 1024,
|
||
"temperature": 0,
|
||
"system": "Json output only without any additional ",
|
||
"messages": messagesData,
|
||
});
|
||
|
||
final response = await http.post(
|
||
Uri.parse('https://api.anthropic.com/v1/messages'),
|
||
headers: {
|
||
'x-api-key': AK.anthropicAIkeySeferNew,
|
||
'anthropic-version': '2023-06-01',
|
||
'content-type': 'application/json'
|
||
},
|
||
body: requestBody,
|
||
);
|
||
|
||
if (response.statusCode == 200) {
|
||
var responseData = jsonDecode(utf8.decode(response.bodyBytes));
|
||
// Process the responseData as needed
|
||
print(responseData);
|
||
if (idType == 'car_back') {
|
||
responseIdCardDriverEgyptBack =
|
||
jsonDecode(responseData['content'][0]['text']);
|
||
} else if (idType == 'car_front') {
|
||
responseIdCardDriverEgyptFront =
|
||
jsonDecode(responseData['content'][0]['text']);
|
||
} else if (idType == 'id_front') {
|
||
responseIdEgyptFront = jsonDecode(responseData['content'][0]['text']);
|
||
} else if (idType == 'id_back') {
|
||
responseIdEgyptBack = jsonDecode(responseData['content'][0]['text']);
|
||
} else if (idType == 'driver_license') {
|
||
responseIdEgyptDriverLicense =
|
||
jsonDecode(responseData['content'][0]['text']);
|
||
} else if (idType == 'criminalRecord') {
|
||
responseCriminalRecordEgypt =
|
||
jsonDecode(responseData['content'][0]['text']);
|
||
}
|
||
|
||
update();
|
||
return responseData.toString();
|
||
}
|
||
return responseIdCardDriverEgyptBack.toString();
|
||
}
|
||
|
||
Future<void> geminiAiExtraction(String prompt, payload, String idType) async {
|
||
var requestBody = jsonEncode({
|
||
"contents": [
|
||
{
|
||
"parts": [
|
||
{"text": "$payload $prompt"}
|
||
]
|
||
}
|
||
],
|
||
"generationConfig": {
|
||
"temperature": 1,
|
||
"topK": 64,
|
||
"topP": 0.95,
|
||
"maxOutputTokens": 8192,
|
||
"stopSequences": []
|
||
},
|
||
"safetySettings": [
|
||
{
|
||
"category": "HARM_CATEGORY_HARASSMENT",
|
||
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
||
},
|
||
{
|
||
"category": "HARM_CATEGORY_HATE_SPEECH",
|
||
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
||
},
|
||
{
|
||
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
||
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
||
},
|
||
{
|
||
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
|
||
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
||
}
|
||
]
|
||
});
|
||
|
||
final response = await http.post(
|
||
Uri.parse(
|
||
// 'https://generativelanguage.googleapis.com/v1beta/models/gemini-pro-vision:generateContent?key=${AK.geminiApi}'),
|
||
// 'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-latest:generateContent?key=${AK.geminiApi}'),
|
||
'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.0-pro:generateContent?key=${AK.geminiApi}'),
|
||
headers: {'Content-Type': 'application/json'},
|
||
body: requestBody,
|
||
);
|
||
|
||
if (response.statusCode == 200) {
|
||
var responseData = jsonDecode(response.body);
|
||
// Process the responseData as needed
|
||
|
||
var result = responseData['candidates'][0]['content']['parts'][0]['text'];
|
||
RegExp regex = RegExp(r"```json([^`]*)```");
|
||
String? jsonString =
|
||
regex.firstMatch(responseData.toString())?.group(1)?.trim();
|
||
|
||
if (jsonString != null) {
|
||
// Convert the JSON object to a String
|
||
jsonString = jsonEncode(json.decode(jsonString));
|
||
|
||
if (idType == 'car_back') {
|
||
responseIdCardDriverEgyptBack = jsonDecode(jsonString);
|
||
} else if (idType == 'car_front') {
|
||
responseIdCardDriverEgyptFront = jsonDecode(jsonString);
|
||
} else if (idType == 'id_front') {
|
||
responseIdEgyptFront = jsonDecode(jsonString);
|
||
} else if (idType == 'id_back') {
|
||
responseIdEgyptBack = jsonDecode(jsonString);
|
||
} else if (idType == 'driver_license') {
|
||
responseIdEgyptDriverLicense = jsonDecode(jsonString);
|
||
}
|
||
|
||
update();
|
||
} else {
|
||
Get.snackbar('Error', "JSON string not found",
|
||
backgroundColor: AppColor.redColor);
|
||
}
|
||
|
||
// Rest of your code...
|
||
} else {}
|
||
}
|
||
|
||
Future<void> getDriverLicenseJordanContent() async {
|
||
await pickImage();
|
||
isloading = true;
|
||
update();
|
||
if (image != null) {
|
||
final imageBytes = await image.readAsBytes();
|
||
final imageData = base64Encode(imageBytes);
|
||
|
||
var requestBody = jsonEncode({
|
||
'contents': [
|
||
{
|
||
'parts': [
|
||
{
|
||
'inlineData': {
|
||
'mimeType': 'image/jpeg',
|
||
'data': imageData,
|
||
},
|
||
},
|
||
{
|
||
'text':
|
||
'write json for all data as first name ,last name,dob,id ,expiration date,issued date asdress class type,age in years ,output json type in arabic value and stay engish key and make date format like YYYY-MM-DD , for name please extract name in arabic in Name in json plus first_name ',
|
||
},
|
||
],
|
||
},
|
||
],
|
||
'generationConfig': {
|
||
'temperature': 0.4,
|
||
'topK': 32,
|
||
'topP': 1,
|
||
'maxOutputTokens': 4096,
|
||
'stopSequences': [],
|
||
},
|
||
'safetySettings': [
|
||
{
|
||
'category': 'HARM_CATEGORY_HARASSMENT',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
{
|
||
'category': 'HARM_CATEGORY_HATE_SPEECH',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
{
|
||
'category': 'HARM_CATEGORY_SEXUALLY_EXPLICIT',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
{
|
||
'category': 'HARM_CATEGORY_DANGEROUS_CONTENT',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
],
|
||
});
|
||
|
||
final response = await http.post(
|
||
Uri.parse(
|
||
'https://generativelanguage.googleapis.com/v1beta/models/gemini-pro-vision:generateContent?key=${AK.geminiApi}'),
|
||
headers: {'Content-Type': 'application/json'},
|
||
body: requestBody,
|
||
);
|
||
isloading = false;
|
||
update();
|
||
if (response.statusCode == 200) {
|
||
var responseData = jsonDecode(response.body);
|
||
// Process the responseData as needed
|
||
|
||
var result =
|
||
responseData['candidates'][0]['content']['parts'][0]['text'];
|
||
RegExp regex = RegExp(r"```json([^`]*)```");
|
||
String? jsonString =
|
||
regex.firstMatch(responseData.toString())?.group(1)?.trim();
|
||
|
||
if (jsonString != null) {
|
||
// Convert the JSON object to a String
|
||
jsonString = jsonEncode(json.decode(jsonString));
|
||
responseMap = jsonDecode(jsonString);
|
||
} else {}
|
||
|
||
// Rest of your code...
|
||
} else {}
|
||
} else {}
|
||
}
|
||
|
||
Future<void> getCarLicenseJordanContent() async {
|
||
await pickImage();
|
||
isloading = true;
|
||
update();
|
||
if (image != null) {
|
||
final imageBytes = await image.readAsBytes();
|
||
final imageData = base64Encode(imageBytes);
|
||
|
||
var requestBody = jsonEncode({
|
||
'contents': [
|
||
{
|
||
'parts': [
|
||
{
|
||
'inlineData': {
|
||
'mimeType': 'image/jpeg',
|
||
'data': imageData,
|
||
},
|
||
},
|
||
{
|
||
'text':
|
||
'''Extract the following information from the front face of the Jordanian ID card:
|
||
Name
|
||
National ID number
|
||
Gender
|
||
Date of birth
|
||
Output the extracted information in the following JSON format''',
|
||
},
|
||
],
|
||
},
|
||
],
|
||
'generationConfig': {
|
||
'temperature': 0.4,
|
||
'topK': 32,
|
||
'topP': 1,
|
||
'maxOutputTokens': 4096,
|
||
'stopSequences': [],
|
||
},
|
||
'safetySettings': [
|
||
{
|
||
'category': 'HARM_CATEGORY_HARASSMENT',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
{
|
||
'category': 'HARM_CATEGORY_HATE_SPEECH',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
{
|
||
'category': 'HARM_CATEGORY_SEXUALLY_EXPLICIT',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
{
|
||
'category': 'HARM_CATEGORY_DANGEROUS_CONTENT',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
],
|
||
});
|
||
|
||
final response = await http.post(
|
||
Uri.parse(
|
||
// 'https://${API_ENDPOINT}/v1/projects/${PROJECT_ID}/locations/${LOCATION_ID}/publishers/google/models/${MODEL_ID}:streamGenerateContent'),
|
||
'https://generativelanguage.googleapis.com/v1beta/models/gemini-pro-vision:generateContent?key=${AK.geminiApi}'),
|
||
headers: {'Content-Type': 'application/json'},
|
||
body: requestBody,
|
||
);
|
||
isloading = false;
|
||
update();
|
||
if (response.statusCode == 200) {
|
||
var responseData = jsonDecode(response.body);
|
||
// Process the responseData as needed
|
||
|
||
var result =
|
||
responseData['candidates'][0]['content']['parts'][0]['text'];
|
||
RegExp regex = RegExp(r"```json([^`]*)```");
|
||
String? jsonString =
|
||
regex.firstMatch(responseData.toString())?.group(1)?.trim();
|
||
|
||
if (jsonString != null) {
|
||
// Convert the JSON object to a String
|
||
jsonString = jsonEncode(json.decode(jsonString));
|
||
responseCarLicenseMapJordan = jsonDecode(jsonString);
|
||
} else {}
|
||
|
||
// Rest of your code...
|
||
} else {}
|
||
} else {}
|
||
}
|
||
|
||
Future<void> jordanID() async {
|
||
await pickImage();
|
||
isloading = true;
|
||
update();
|
||
if (image != null) {
|
||
final imageBytes = await image.readAsBytes();
|
||
final imageData = base64Encode(imageBytes);
|
||
|
||
var requestBody = jsonEncode({
|
||
'contents': [
|
||
{
|
||
'parts': [
|
||
{
|
||
'inlineData': {
|
||
'mimeType': 'image/jpeg',
|
||
'data': imageData,
|
||
},
|
||
},
|
||
{
|
||
'text':
|
||
'''Extract the following information from the front face of the Jordanian ID card:
|
||
Name
|
||
National ID number
|
||
Gender
|
||
Date of birth
|
||
Output the extracted information in the following JSON format''',
|
||
},
|
||
],
|
||
},
|
||
],
|
||
'generationConfig': {
|
||
'temperature': 0.4,
|
||
'topK': 32,
|
||
'topP': 1,
|
||
'maxOutputTokens': 4096,
|
||
'stopSequences': [],
|
||
},
|
||
'safetySettings': [
|
||
{
|
||
'category': 'HARM_CATEGORY_HARASSMENT',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
{
|
||
'category': 'HARM_CATEGORY_HATE_SPEECH',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
{
|
||
'category': 'HARM_CATEGORY_SEXUALLY_EXPLICIT',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
{
|
||
'category': 'HARM_CATEGORY_DANGEROUS_CONTENT',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
],
|
||
});
|
||
|
||
final response = await http.post(
|
||
Uri.parse(
|
||
'https://generativelanguage.googleapis.com/v1beta/models/gemini-pro-vision:generateContent?key=${AK.geminiApi}'),
|
||
headers: {'Content-Type': 'application/json'},
|
||
body: requestBody,
|
||
);
|
||
isloading = false;
|
||
update();
|
||
if (response.statusCode == 200) {
|
||
var responseData = jsonDecode(response.body);
|
||
// Process the responseData as needed
|
||
|
||
var result =
|
||
responseData['candidates'][0]['content']['parts'][0]['text'];
|
||
RegExp regex = RegExp(r"```json([^`]*)```");
|
||
String? jsonString =
|
||
regex.firstMatch(responseData.toString())?.group(1)?.trim();
|
||
|
||
if (jsonString != null) {
|
||
// Convert the JSON object to a String
|
||
jsonString = jsonEncode(json.decode(jsonString));
|
||
responseCarLicenseMapJordan = jsonDecode(jsonString);
|
||
} else {}
|
||
|
||
// Rest of your code...
|
||
} else {}
|
||
} else {}
|
||
}
|
||
|
||
Future<void> carLicenseJordan() async {
|
||
await pickImage();
|
||
isloading = true;
|
||
update();
|
||
if (image != null) {
|
||
final imageBytes = await image.readAsBytes();
|
||
final imageData = base64Encode(imageBytes);
|
||
|
||
var requestBody = jsonEncode({
|
||
'contents': [
|
||
{
|
||
'parts': [
|
||
{
|
||
'inlineData': {
|
||
'mimeType': 'image/jpeg',
|
||
'data': imageData,
|
||
},
|
||
},
|
||
{
|
||
'text':
|
||
'''Extract the following information from the front face of the car license card in Jordan:
|
||
|
||
* name
|
||
* Address
|
||
* Vehicle type
|
||
* car_kind
|
||
* car_color
|
||
* Vehicle category
|
||
* car_year
|
||
* car_plate
|
||
* Registration type
|
||
* Usage type
|
||
* expire_date_of_license
|
||
|
||
Output the extracted information in the following JSON formate and make date format like YYYY-MM-DD''',
|
||
},
|
||
],
|
||
},
|
||
],
|
||
'generationConfig': {
|
||
'temperature': 0.4,
|
||
'topK': 32,
|
||
'topP': 1,
|
||
'maxOutputTokens': 4096,
|
||
'stopSequences': [],
|
||
},
|
||
'safetySettings': [
|
||
{
|
||
'category': 'HARM_CATEGORY_HARASSMENT',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
{
|
||
'category': 'HARM_CATEGORY_HATE_SPEECH',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
{
|
||
'category': 'HARM_CATEGORY_SEXUALLY_EXPLICIT',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
{
|
||
'category': 'HARM_CATEGORY_DANGEROUS_CONTENT',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
],
|
||
});
|
||
|
||
final response = await http.post(
|
||
Uri.parse(
|
||
'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.0-pro-vision-latest:generateContent?key=${AK.geminiApi}'),
|
||
headers: {'Content-Type': 'application/json'},
|
||
body: requestBody,
|
||
);
|
||
isloading = false;
|
||
update();
|
||
if (response.statusCode == 200) {
|
||
var responseData = jsonDecode(response.body);
|
||
// Process the responseData as needed
|
||
|
||
var result =
|
||
responseData['candidates'][0]['content']['parts'][0]['text'];
|
||
RegExp regex = RegExp(r"```json([^`]*)```");
|
||
String? jsonString =
|
||
regex.firstMatch(responseData.toString())?.group(1)?.trim();
|
||
|
||
if (jsonString != null) {
|
||
// Convert the JSON object to a String
|
||
jsonString = jsonEncode(json.decode(jsonString));
|
||
responseCarLicenseMapJordan = jsonDecode(jsonString);
|
||
} else {}
|
||
|
||
// Rest of your code...
|
||
} else {}
|
||
} else {}
|
||
}
|
||
|
||
Future getTextFromCard(String prompt) async {
|
||
await pickImage();
|
||
isloading = true;
|
||
update();
|
||
if (image != null) {
|
||
final imageBytes = await image.readAsBytes();
|
||
final imageData = base64Encode(imageBytes);
|
||
|
||
var requestBody = jsonEncode({
|
||
'contents': [
|
||
{
|
||
'parts': [
|
||
{
|
||
'inlineData': {
|
||
'mimeType': 'image/jpeg',
|
||
'data': imageData,
|
||
},
|
||
},
|
||
{
|
||
'text': prompt,
|
||
},
|
||
],
|
||
},
|
||
],
|
||
'generationConfig': {
|
||
"temperature": 1,
|
||
"topK": 32,
|
||
"topP": 0.1,
|
||
"maxOutputTokens": 4096,
|
||
"stopSequences": []
|
||
},
|
||
'safetySettings': [
|
||
{
|
||
'category': 'HARM_CATEGORY_HARASSMENT',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
{
|
||
'category': 'HARM_CATEGORY_HATE_SPEECH',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
{
|
||
'category': 'HARM_CATEGORY_SEXUALLY_EXPLICIT',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
{
|
||
'category': 'HARM_CATEGORY_DANGEROUS_CONTENT',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
],
|
||
});
|
||
|
||
final response = await http.post(
|
||
Uri.parse(
|
||
'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.0-pro-vision-latest:generateContent?key=${AK.geminiApi}'),
|
||
headers: {'Content-Type': 'application/json'},
|
||
body: requestBody,
|
||
);
|
||
isloading = false;
|
||
update();
|
||
if (response.statusCode == 200) {
|
||
var responseData = jsonDecode(response.body);
|
||
// Process the responseData as needed
|
||
|
||
var result =
|
||
responseData['candidates'][0]['content']['parts'][0]['text'];
|
||
RegExp regex = RegExp(r"```json([^`]*)```");
|
||
String? jsonString =
|
||
regex.firstMatch(responseData.toString())?.group(1)?.trim();
|
||
|
||
if (jsonString != null) {
|
||
// Convert the JSON object to a String
|
||
jsonString = jsonEncode(json.decode(jsonString));
|
||
responseBackCarLicenseMap = jsonDecode(jsonString);
|
||
} else {}
|
||
|
||
// Rest of your code...
|
||
} else {}
|
||
} else {}
|
||
}
|
||
|
||
Future<void> generateBackCarLicenseJordanContent() async {
|
||
await pickImage();
|
||
isloading = true;
|
||
update();
|
||
if (image != null) {
|
||
final imageBytes = await image.readAsBytes();
|
||
final imageData = base64Encode(imageBytes);
|
||
|
||
var requestBody = jsonEncode({
|
||
'contents': [
|
||
{
|
||
'parts': [
|
||
{
|
||
'inlineData': {
|
||
'mimeType': 'image/jpeg',
|
||
'data': imageData,
|
||
},
|
||
},
|
||
{
|
||
'text':
|
||
'write json output from extracting car license back face for these key ,vin,fuelType,passengerType,curbWeight,insuranceCompany,policyNumber,notes,insuranceType and output it json .dont add data else this image',
|
||
},
|
||
],
|
||
},
|
||
],
|
||
'generationConfig': {
|
||
'temperature': 0.4,
|
||
'topK': 343,
|
||
'topP': 1,
|
||
'maxOutputTokens': 4096,
|
||
'stopSequences': [],
|
||
},
|
||
'safetySettings': [
|
||
{
|
||
'category': 'HARM_CATEGORY_HARASSMENT',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
{
|
||
'category': 'HARM_CATEGORY_HATE_SPEECH',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
{
|
||
'category': 'HARM_CATEGORY_SEXUALLY_EXPLICIT',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
{
|
||
'category': 'HARM_CATEGORY_DANGEROUS_CONTENT',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
],
|
||
});
|
||
|
||
final response = await http.post(
|
||
Uri.parse(
|
||
'https://generativelanguage.googleapis.com/v1beta/models/gemini-pro-vision:generateContent?key=${AK.geminiApi}'),
|
||
headers: {'Content-Type': 'application/json'},
|
||
body: requestBody,
|
||
);
|
||
isloading = false;
|
||
update();
|
||
if (response.statusCode == 200) {
|
||
var responseData = jsonDecode(response.body);
|
||
// Process the responseData as needed
|
||
|
||
var result =
|
||
responseData['candidates'][0]['content']['parts'][0]['text'];
|
||
RegExp regex = RegExp(r"```json([^`]*)```");
|
||
String? jsonString =
|
||
regex.firstMatch(responseData.toString())?.group(1)?.trim();
|
||
|
||
if (jsonString != null) {
|
||
// Convert the JSON object to a String
|
||
jsonString = jsonEncode(json.decode(jsonString));
|
||
responseBackCarLicenseMap = jsonDecode(jsonString);
|
||
} else {}
|
||
|
||
// Rest of your code...
|
||
} else {}
|
||
} else {}
|
||
}
|
||
|
||
Future<void> getFromCarRegistration() async {
|
||
await pickImage();
|
||
if (image != null) {
|
||
final imageBytes = await image.readAsBytes();
|
||
final imageData = base64Encode(imageBytes);
|
||
|
||
var requestBody = jsonEncode({
|
||
'contents': [
|
||
{
|
||
'parts': [
|
||
{
|
||
'inlineData': {
|
||
'mimeType': 'image/jpeg',
|
||
'data': imageData,
|
||
},
|
||
},
|
||
{
|
||
'text':
|
||
'write output json from image for[ vin, make, model, year, expiration_date, color, owner, registration_date ],output json type ',
|
||
},
|
||
],
|
||
},
|
||
],
|
||
'generationConfig': {
|
||
'temperature': 0.4,
|
||
'topK': 32,
|
||
'topP': 1,
|
||
'maxOutputTokens': 4096,
|
||
'stopSequences': [],
|
||
},
|
||
'safetySettings': [
|
||
{
|
||
'category': 'HARM_CATEGORY_HARASSMENT',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
{
|
||
'category': 'HARM_CATEGORY_HATE_SPEECH',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
{
|
||
'category': 'HARM_CATEGORY_SEXUALLY_EXPLICIT',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
{
|
||
'category': 'HARM_CATEGORY_DANGEROUS_CONTENT',
|
||
'threshold': 'BLOCK_MEDIUM_AND_ABOVE',
|
||
},
|
||
],
|
||
});
|
||
|
||
final response = await http.post(
|
||
Uri.parse(
|
||
'https://generativelanguage.googleapis.com/v1beta/models/gemini-pro-vision:generateContent?key=${AK.geminiApi}'),
|
||
headers: {'Content-Type': 'application/json'},
|
||
body: requestBody,
|
||
);
|
||
|
||
if (response.statusCode == 200) {
|
||
var responseData = jsonDecode(response.body);
|
||
// Process the responseData as needed
|
||
var result =
|
||
responseData['candidates'][0]['content']['parts'][0]['text'];
|
||
RegExp regex = RegExp(r"```json([^`]*)```");
|
||
String? jsonString =
|
||
regex.firstMatch(responseData.toString())?.group(1)?.trim();
|
||
|
||
if (jsonString != null) {
|
||
// Convert the JSON object to a String
|
||
jsonString = jsonEncode(json.decode(jsonString));
|
||
} else {}
|
||
|
||
// Rest of your code...
|
||
} else {}
|
||
} else {}
|
||
}
|
||
|
||
@override
|
||
void onInit() {
|
||
// generateContent();
|
||
super.onInit();
|
||
}
|
||
}
|