7/17/2
This commit is contained in:
@@ -8,6 +8,7 @@ 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:SEFER/views/widgets/mydialoug.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:image_cropper/image_cropper.dart';
|
||||
@@ -21,6 +22,21 @@ import '../../constant/colors.dart';
|
||||
import 'tts.dart';
|
||||
import 'upload_image.dart';
|
||||
|
||||
enum LicenseSide {
|
||||
front,
|
||||
back,
|
||||
unknown,
|
||||
}
|
||||
|
||||
enum DocumentType {
|
||||
carLicenseFront,
|
||||
carLicenseBack,
|
||||
idCardFront,
|
||||
idCardBack,
|
||||
driverLicense,
|
||||
unknown,
|
||||
}
|
||||
|
||||
class AI extends GetxController {
|
||||
bool approved = false;
|
||||
bool isDriverSaved = false;
|
||||
@@ -306,90 +322,6 @@ class AI extends GetxController {
|
||||
// }
|
||||
}
|
||||
|
||||
// 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);
|
||||
// // }
|
||||
// }
|
||||
addCriminalDeocuments() async {
|
||||
var res = await CRUD().post(link: AppLink.addCriminalDocuments, payload: {
|
||||
"driverId": box.read(BoxName.driverID),
|
||||
@@ -448,9 +380,11 @@ class AI extends GetxController {
|
||||
Map<String, dynamic> responseIdEgyptDriverLicense = {};
|
||||
String? responseIdCardDriverEgypt1;
|
||||
bool isloading = false;
|
||||
bool isLoading = false;
|
||||
var image;
|
||||
CroppedFile? croppedFile;
|
||||
DateTime now = DateTime.now();
|
||||
|
||||
Future<void> pickImage() async {
|
||||
final pickedImage = await picker.pickImage(source: ImageSource.gallery);
|
||||
|
||||
@@ -498,23 +432,121 @@ class AI extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
bool isLoading = false;
|
||||
Future allMethodForAI(String prompt, linkPHP, imagePath) async {
|
||||
DocumentType checkDocumentType(String text) {
|
||||
// Convert text to lowercase and remove all spaces and new lines
|
||||
text = text.toLowerCase().replaceAll(RegExp(r'\s+'), '');
|
||||
|
||||
// Keywords for each document type
|
||||
final Map<DocumentType, List<String>> keywords = {
|
||||
DocumentType.carLicenseBack: ['شاسيه', 'موتور', 'سم٣'],
|
||||
DocumentType.carLicenseFront: ['وزارةالداخلية', 'رخصةتسيير'],
|
||||
DocumentType.idCardFront: ['بطاقةتحقيقالشخصية'],
|
||||
DocumentType.idCardBack: ['البطاقةساريةحتى'],
|
||||
DocumentType.driverLicense: ['قيادةخاصة', 'خاصه'],
|
||||
};
|
||||
|
||||
// Check each document type
|
||||
for (var entry in keywords.entries) {
|
||||
if (entry.value.any((keyword) => text.contains(keyword))) {
|
||||
return entry.key;
|
||||
}
|
||||
}
|
||||
|
||||
// If no match is found
|
||||
return DocumentType.unknown;
|
||||
}
|
||||
|
||||
Future<void> allMethodForAI(
|
||||
String prompt, String linkPHP, String 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();
|
||||
|
||||
try {
|
||||
await ImageController().choosImage(linkPHP, imagePath);
|
||||
await Future.delayed(const Duration(seconds: 2));
|
||||
|
||||
var extractedString =
|
||||
await CRUD().arabicTextExtractByVisionAndAI(imagePath: imagePath);
|
||||
var json = jsonDecode(extractedString);
|
||||
var textValues = CRUD().extractTextFromLines(json);
|
||||
print('textValues: ${textValues}');
|
||||
|
||||
DocumentType detectedType = checkDocumentType(textValues);
|
||||
String expectedDocument = getExpectedDocument(imagePath);
|
||||
String detectedDocument = getDetectedDocument(detectedType);
|
||||
|
||||
bool isCorrectDocument = (detectedType == getExpectedType(imagePath));
|
||||
|
||||
if (!isCorrectDocument) {
|
||||
MyDialog().getDialog('incorrect_document_title'.tr,
|
||||
'${'expected'.tr}: $expectedDocument\n${'detected'.tr}: $detectedDocument',
|
||||
() {
|
||||
Get.back();
|
||||
});
|
||||
} else {
|
||||
// Process the correct document
|
||||
await Get.put(AI()).anthropicAI(textValues, prompt, imagePath);
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error in allMethodForAI: $e');
|
||||
MyDialog().getDialog('error'.tr, 'error_processing_document'.tr, () {
|
||||
Get.back();
|
||||
});
|
||||
} finally {
|
||||
isLoading = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
String getExpectedDocument(String imagePath) {
|
||||
switch (imagePath) {
|
||||
case 'car_front':
|
||||
return 'car_license_front'.tr;
|
||||
case 'car_back':
|
||||
return 'car_license_back'.tr;
|
||||
case 'id_back':
|
||||
return 'id_card_back'.tr;
|
||||
case 'id_front':
|
||||
return 'id_card_front'.tr;
|
||||
case 'driver_license':
|
||||
return 'driver_license'.tr;
|
||||
default:
|
||||
return 'unknown_document'.tr;
|
||||
}
|
||||
}
|
||||
|
||||
DocumentType getExpectedType(String imagePath) {
|
||||
switch (imagePath) {
|
||||
case 'car_front':
|
||||
return DocumentType.carLicenseFront;
|
||||
case 'car_back':
|
||||
return DocumentType.carLicenseBack;
|
||||
case 'id_back':
|
||||
return DocumentType.idCardBack;
|
||||
case 'id_front':
|
||||
return DocumentType.idCardFront;
|
||||
case 'driver_license':
|
||||
return DocumentType.driverLicense;
|
||||
default:
|
||||
return DocumentType.unknown;
|
||||
}
|
||||
}
|
||||
|
||||
String getDetectedDocument(DocumentType type) {
|
||||
switch (type) {
|
||||
case DocumentType.carLicenseFront:
|
||||
return 'car_license_front'.tr;
|
||||
case DocumentType.carLicenseBack:
|
||||
return 'car_license_back'.tr;
|
||||
case DocumentType.idCardFront:
|
||||
return 'id_card_front'.tr;
|
||||
case DocumentType.idCardBack:
|
||||
return 'id_card_back'.tr;
|
||||
case DocumentType.driverLicense:
|
||||
return 'driver_license'.tr;
|
||||
default:
|
||||
return 'unknown_document'.tr;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> generateContent() async {
|
||||
|
||||
Reference in New Issue
Block a user