This commit is contained in:
Hamza-Ayed
2024-07-20 14:18:06 +03:00
parent 27de944c2f
commit bdb910f3c2
14 changed files with 186 additions and 126 deletions

View File

@@ -16,9 +16,12 @@ 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 'package:secure_string_operations/secure_string_operations.dart';
import '../../constant/api_key.dart';
import '../../constant/char_map.dart';
import '../../constant/colors.dart';
import '../../print.dart';
import 'tts.dart';
import 'upload_image.dart';
@@ -157,44 +160,45 @@ class AI extends GetxController {
),
],
);
} 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 drivers 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 drivers license does not match the one on your ID document. Please verify and provide the correct documents."
.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'.tr,
// 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 drivers 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 drivers license does not match the one on your ID document. Please verify and provide the correct documents."
// .tr,
// );
// },
// icon: const Icon(Icons.volume_up),
// ),
// ],
// ),
// actions: [
// TextButton(
// onPressed: () {
// Get.back();
// },
// child: const Text('OK'),
// ),
// ],
// );
// }
// else if (responseCriminalRecordEgypt['FullName'] !=
// responseIdEgyptDriverLicense['name_arabic']) {
// Get.defaultDialog(
@@ -304,7 +308,6 @@ class AI extends GetxController {
var status1 = jsonDecode(res);
isLoading = false;
update();
print(res);
// Handle response
if (status1['status'] == 'success') {
isDriverSaved = true;
@@ -471,13 +474,13 @@ class AI extends GetxController {
// if (imagePath == 'driver_license') {
// await ImageController().choosFaceFromDriverLicense(linkPHP, 'face');
// }
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);
@@ -496,7 +499,6 @@ class AI extends GetxController {
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();
});
@@ -681,7 +683,6 @@ class AI extends GetxController {
if (response.statusCode == 200) {
var responseData = jsonDecode(utf8.decode(response.bodyBytes));
// Process the responseData as needed
print(responseData);
responseForComplaint = jsonDecode(responseData['content'][0]['text']);
}
@@ -697,7 +698,7 @@ class AI extends GetxController {
]
}
];
var k = X.r(X.r(X.r(await getAIKey('CLAUDAISEFER'), cn), cC), cs);
var requestBody = jsonEncode({
"model": "claude-3-haiku-20240307",
"max_tokens": 1024,
@@ -709,7 +710,7 @@ class AI extends GetxController {
final response = await http.post(
Uri.parse('https://api.anthropic.com/v1/messages'),
headers: {
'x-api-key': AK.anthropicAIkeySeferNew,
'x-api-key': k,
'anthropic-version': '2023-06-01',
'content-type': 'application/json'
},
@@ -719,7 +720,6 @@ class AI extends GetxController {
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']);
@@ -1417,10 +1417,16 @@ Output the extracted information in the following JSON formate and make date for
if (res != 'failure') {
var d = jsonDecode(res)['message'];
prompts = d;
// print('prompts: ${prompts}');
} else {
print(res);
}
} else {}
}
getAIKey(String key) async {
var res =
await CRUD().get(link: AppLink.getapiKey, payload: {"keyName": key});
if (res != 'failure') {
var d = jsonDecode(res)['message'];
return d[key].toString();
} else {}
}
@override