6/22/1
This commit is contained in:
@@ -208,20 +208,6 @@ class AI extends GetxController {
|
||||
|
||||
Future<void> addDriverEgypt() async {
|
||||
try {
|
||||
print(box.read(BoxName.driverID).toString());
|
||||
print(box.read(BoxName.phoneDriver)?.toString() ?? '');
|
||||
print(responseIdEgyptBack['gender']);
|
||||
print(responseIdEgyptDriverLicense['license_type']);
|
||||
print(responseIdEgyptBack['nationalID']);
|
||||
print(responseIdEgyptDriverLicense['issue_date']);
|
||||
print(responseIdEgyptDriverLicense['expiry_date']);
|
||||
print(responseIdEgyptDriverLicense['license_categories']);
|
||||
print(responseIdEgyptFront['card_id']);
|
||||
print(responseIdEgyptDriverLicense['issue_date']);
|
||||
print(responseIdEgyptFront['dob'] != null
|
||||
? responseIdEgyptFront['dob'] + '-01-01'.toString()
|
||||
: '');
|
||||
|
||||
// Extract values from box or set defaults
|
||||
var firstName = responseIdEgyptDriverLicense['firstName'] ?? '';
|
||||
var lastName = responseIdEgyptDriverLicense['lastName'] ?? '';
|
||||
@@ -282,7 +268,6 @@ class AI extends GetxController {
|
||||
'site': site,
|
||||
'employmentType': employmentType,
|
||||
};
|
||||
print(payload);
|
||||
isLoading = true;
|
||||
update();
|
||||
// Make POST request
|
||||
@@ -292,7 +277,6 @@ class AI extends GetxController {
|
||||
update();
|
||||
// Handle response
|
||||
|
||||
print(status1);
|
||||
if (status1['status'] == 'success') {
|
||||
isDriverSaved = true;
|
||||
Get.snackbar('Success', 'Driver data saved successfully',
|
||||
@@ -302,7 +286,6 @@ class AI extends GetxController {
|
||||
backgroundColor: Colors.red);
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error: $e');
|
||||
Get.snackbar('Error', 'An error occurred while saving driver data',
|
||||
backgroundColor: Colors.red);
|
||||
}
|
||||
@@ -338,9 +321,7 @@ class AI extends GetxController {
|
||||
Get.snackbar('Success', 'message',
|
||||
backgroundColor: AppColor.greenColor);
|
||||
}
|
||||
} catch (e) {
|
||||
print('error is $e');
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
final picker = ImagePicker();
|
||||
@@ -414,10 +395,8 @@ class AI extends GetxController {
|
||||
Future.delayed(const Duration(seconds: 2));
|
||||
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;
|
||||
@@ -473,7 +452,6 @@ class AI extends GetxController {
|
||||
},
|
||||
],
|
||||
});
|
||||
print(requestBody);
|
||||
|
||||
final response = await http.post(
|
||||
Uri.parse(
|
||||
@@ -485,13 +463,9 @@ class AI extends GetxController {
|
||||
if (response.statusCode == 200) {
|
||||
var responseData = jsonDecode(response.body);
|
||||
// Process the responseData as needed
|
||||
// print(responseData);
|
||||
|
||||
var result =
|
||||
responseData['candidates'][0]['content']['parts'][0]['text'];
|
||||
// print(jsonEncode(result));
|
||||
// print((result));
|
||||
// print(result['dob']);
|
||||
RegExp regex = RegExp(r"```json([^`]*)```");
|
||||
String? jsonString =
|
||||
regex.firstMatch(responseData.toString())?.group(1)?.trim();
|
||||
@@ -499,19 +473,11 @@ class AI extends GetxController {
|
||||
if (jsonString != null) {
|
||||
// Convert the JSON object to a String
|
||||
jsonString = jsonEncode(json.decode(jsonString));
|
||||
print(jsonString);
|
||||
} else {
|
||||
print("JSON string not found");
|
||||
}
|
||||
} else {}
|
||||
|
||||
// Rest of your code...
|
||||
} else {
|
||||
print('Request failed with status: ${response.statusCode}');
|
||||
print('Request failed with status: ${response.body}');
|
||||
}
|
||||
} else {
|
||||
print('No image selected');
|
||||
}
|
||||
} else {}
|
||||
} else {}
|
||||
}
|
||||
|
||||
Future<dynamic> anthropicAI(
|
||||
@@ -533,9 +499,6 @@ class AI extends GetxController {
|
||||
"messages": messagesData,
|
||||
});
|
||||
|
||||
print('requestBody');
|
||||
print(requestBody);
|
||||
|
||||
final response = await http.post(
|
||||
Uri.parse('https://api.anthropic.com/v1/messages'),
|
||||
headers: {
|
||||
@@ -549,29 +512,22 @@ class AI extends GetxController {
|
||||
if (response.statusCode == 200) {
|
||||
var responseData = jsonDecode(utf8.decode(response.bodyBytes));
|
||||
// Process the responseData as needed
|
||||
print(utf8.decode(response.bodyBytes));
|
||||
if (idType == 'car_back') {
|
||||
responseIdCardDriverEgyptBack =
|
||||
jsonDecode(responseData['content'][0]['text']);
|
||||
print(responseIdCardDriverEgyptBack);
|
||||
} else if (idType == 'car_front') {
|
||||
responseIdCardDriverEgyptFront =
|
||||
jsonDecode(responseData['content'][0]['text']);
|
||||
print(responseIdCardDriverEgyptFront);
|
||||
} else if (idType == 'id_front') {
|
||||
responseIdEgyptFront = jsonDecode(responseData['content'][0]['text']);
|
||||
print(responseIdEgyptFront);
|
||||
} else if (idType == 'id_back') {
|
||||
responseIdEgyptBack = jsonDecode(responseData['content'][0]['text']);
|
||||
print(responseIdEgyptBack);
|
||||
} else if (idType == 'driver_license') {
|
||||
responseIdEgyptDriverLicense =
|
||||
jsonDecode(responseData['content'][0]['text']);
|
||||
print(responseIdEgyptDriverLicense);
|
||||
} else if (idType == 'criminalRecord') {
|
||||
responseCriminalRecordEgypt =
|
||||
jsonDecode(responseData['content'][0]['text']);
|
||||
print(responseCriminalRecordEgypt);
|
||||
}
|
||||
|
||||
update();
|
||||
@@ -615,7 +571,6 @@ class AI extends GetxController {
|
||||
}
|
||||
]
|
||||
});
|
||||
// print(requestBody);
|
||||
|
||||
final response = await http.post(
|
||||
Uri.parse(
|
||||
@@ -629,12 +584,8 @@ class AI extends GetxController {
|
||||
if (response.statusCode == 200) {
|
||||
var responseData = jsonDecode(response.body);
|
||||
// Process the responseData as needed
|
||||
// print(responseData);
|
||||
|
||||
var result = responseData['candidates'][0]['content']['parts'][0]['text'];
|
||||
// print(jsonEncode(result));
|
||||
// print((result));
|
||||
// print(result['dob']);
|
||||
RegExp regex = RegExp(r"```json([^`]*)```");
|
||||
String? jsonString =
|
||||
regex.firstMatch(responseData.toString())?.group(1)?.trim();
|
||||
@@ -645,33 +596,24 @@ class AI extends GetxController {
|
||||
|
||||
if (idType == 'car_back') {
|
||||
responseIdCardDriverEgyptBack = jsonDecode(jsonString);
|
||||
print(responseIdCardDriverEgyptBack);
|
||||
} else if (idType == 'car_front') {
|
||||
responseIdCardDriverEgyptFront = jsonDecode(jsonString);
|
||||
print(responseIdCardDriverEgyptFront);
|
||||
} else if (idType == 'id_front') {
|
||||
responseIdEgyptFront = jsonDecode(jsonString);
|
||||
print(responseIdEgyptFront);
|
||||
} else if (idType == 'id_back') {
|
||||
responseIdEgyptBack = jsonDecode(jsonString);
|
||||
print(responseIdEgyptBack);
|
||||
} else if (idType == 'driver_license') {
|
||||
responseIdEgyptDriverLicense = jsonDecode(jsonString);
|
||||
print(responseIdEgyptDriverLicense);
|
||||
}
|
||||
|
||||
update();
|
||||
} else {
|
||||
print("JSON string not found");
|
||||
Get.snackbar('Error', "JSON string not found",
|
||||
backgroundColor: AppColor.redColor);
|
||||
}
|
||||
|
||||
// Rest of your code...
|
||||
} else {
|
||||
print('Request failed with status: ${response.statusCode}');
|
||||
print('Request failed with status: ${response.body}');
|
||||
}
|
||||
} else {}
|
||||
}
|
||||
|
||||
Future<void> getDriverLicenseJordanContent() async {
|
||||
@@ -725,7 +667,6 @@ class AI extends GetxController {
|
||||
},
|
||||
],
|
||||
});
|
||||
print(requestBody);
|
||||
|
||||
final response = await http.post(
|
||||
Uri.parse(
|
||||
@@ -738,13 +679,9 @@ class AI extends GetxController {
|
||||
if (response.statusCode == 200) {
|
||||
var responseData = jsonDecode(response.body);
|
||||
// Process the responseData as needed
|
||||
// print(responseData);
|
||||
|
||||
var result =
|
||||
responseData['candidates'][0]['content']['parts'][0]['text'];
|
||||
// print(jsonEncode(result));
|
||||
// print((result));
|
||||
// print(result['dob']);
|
||||
RegExp regex = RegExp(r"```json([^`]*)```");
|
||||
String? jsonString =
|
||||
regex.firstMatch(responseData.toString())?.group(1)?.trim();
|
||||
@@ -753,21 +690,11 @@ class AI extends GetxController {
|
||||
// Convert the JSON object to a String
|
||||
jsonString = jsonEncode(json.decode(jsonString));
|
||||
responseMap = jsonDecode(jsonString);
|
||||
print(jsonString);
|
||||
print(responseMap);
|
||||
print(responseMap['dob']);
|
||||
} else {
|
||||
print("JSON string not found");
|
||||
}
|
||||
} else {}
|
||||
|
||||
// Rest of your code...
|
||||
} else {
|
||||
print('Request failed with status: ${response.statusCode}');
|
||||
print('Request failed with status: ${response.body}');
|
||||
}
|
||||
} else {
|
||||
print('No image selected');
|
||||
}
|
||||
} else {}
|
||||
} else {}
|
||||
}
|
||||
|
||||
Future<void> getCarLicenseJordanContent() async {
|
||||
@@ -826,7 +753,6 @@ Output the extracted information in the following JSON format''',
|
||||
},
|
||||
],
|
||||
});
|
||||
print(requestBody);
|
||||
|
||||
final response = await http.post(
|
||||
Uri.parse(
|
||||
@@ -840,13 +766,9 @@ Output the extracted information in the following JSON format''',
|
||||
if (response.statusCode == 200) {
|
||||
var responseData = jsonDecode(response.body);
|
||||
// Process the responseData as needed
|
||||
// print(responseData);
|
||||
|
||||
var result =
|
||||
responseData['candidates'][0]['content']['parts'][0]['text'];
|
||||
// print(jsonEncode(result));
|
||||
// print((result));
|
||||
// print(result['dob']);
|
||||
RegExp regex = RegExp(r"```json([^`]*)```");
|
||||
String? jsonString =
|
||||
regex.firstMatch(responseData.toString())?.group(1)?.trim();
|
||||
@@ -855,21 +777,11 @@ Output the extracted information in the following JSON format''',
|
||||
// Convert the JSON object to a String
|
||||
jsonString = jsonEncode(json.decode(jsonString));
|
||||
responseCarLicenseMapJordan = jsonDecode(jsonString);
|
||||
print(jsonString);
|
||||
print(responseCarLicenseMapJordan);
|
||||
print(responseCarLicenseMapJordan['plate_number']);
|
||||
} else {
|
||||
print("JSON string not found");
|
||||
}
|
||||
} else {}
|
||||
|
||||
// Rest of your code...
|
||||
} else {
|
||||
print('Request failed with status: ${response.statusCode}');
|
||||
print('Request failed with status: ${response.body}');
|
||||
}
|
||||
} else {
|
||||
print('No image selected');
|
||||
}
|
||||
} else {}
|
||||
} else {}
|
||||
}
|
||||
|
||||
Future<void> jordanID() async {
|
||||
@@ -928,7 +840,6 @@ Output the extracted information in the following JSON format''',
|
||||
},
|
||||
],
|
||||
});
|
||||
print(requestBody);
|
||||
|
||||
final response = await http.post(
|
||||
Uri.parse(
|
||||
@@ -941,13 +852,9 @@ Output the extracted information in the following JSON format''',
|
||||
if (response.statusCode == 200) {
|
||||
var responseData = jsonDecode(response.body);
|
||||
// Process the responseData as needed
|
||||
// print(responseData);
|
||||
|
||||
var result =
|
||||
responseData['candidates'][0]['content']['parts'][0]['text'];
|
||||
// print(jsonEncode(result));
|
||||
// print((result));
|
||||
// print(result['dob']);
|
||||
RegExp regex = RegExp(r"```json([^`]*)```");
|
||||
String? jsonString =
|
||||
regex.firstMatch(responseData.toString())?.group(1)?.trim();
|
||||
@@ -956,21 +863,11 @@ Output the extracted information in the following JSON format''',
|
||||
// Convert the JSON object to a String
|
||||
jsonString = jsonEncode(json.decode(jsonString));
|
||||
responseCarLicenseMapJordan = jsonDecode(jsonString);
|
||||
print(jsonString);
|
||||
print(responseCarLicenseMapJordan);
|
||||
print(responseCarLicenseMapJordan['plate_number']);
|
||||
} else {
|
||||
print("JSON string not found");
|
||||
}
|
||||
} else {}
|
||||
|
||||
// Rest of your code...
|
||||
} else {
|
||||
print('Request failed with status: ${response.statusCode}');
|
||||
print('Request failed with status: ${response.body}');
|
||||
}
|
||||
} else {
|
||||
print('No image selected');
|
||||
}
|
||||
} else {}
|
||||
} else {}
|
||||
}
|
||||
|
||||
Future<void> carLicenseJordan() async {
|
||||
@@ -1038,7 +935,6 @@ Output the extracted information in the following JSON formate and make date for
|
||||
},
|
||||
],
|
||||
});
|
||||
print(requestBody);
|
||||
|
||||
final response = await http.post(
|
||||
Uri.parse(
|
||||
@@ -1051,13 +947,9 @@ Output the extracted information in the following JSON formate and make date for
|
||||
if (response.statusCode == 200) {
|
||||
var responseData = jsonDecode(response.body);
|
||||
// Process the responseData as needed
|
||||
// print(responseData);
|
||||
|
||||
var result =
|
||||
responseData['candidates'][0]['content']['parts'][0]['text'];
|
||||
// print(jsonEncode(result));
|
||||
// print((result));
|
||||
// print(result['dob']);
|
||||
RegExp regex = RegExp(r"```json([^`]*)```");
|
||||
String? jsonString =
|
||||
regex.firstMatch(responseData.toString())?.group(1)?.trim();
|
||||
@@ -1066,21 +958,11 @@ Output the extracted information in the following JSON formate and make date for
|
||||
// Convert the JSON object to a String
|
||||
jsonString = jsonEncode(json.decode(jsonString));
|
||||
responseCarLicenseMapJordan = jsonDecode(jsonString);
|
||||
print(jsonString);
|
||||
print(responseCarLicenseMapJordan);
|
||||
print(responseCarLicenseMapJordan['plate_number']);
|
||||
} else {
|
||||
print("JSON string not found");
|
||||
}
|
||||
} else {}
|
||||
|
||||
// Rest of your code...
|
||||
} else {
|
||||
print('Request failed with status: ${response.statusCode}');
|
||||
print('Request failed with status: ${response.body}');
|
||||
}
|
||||
} else {
|
||||
print('No image selected');
|
||||
}
|
||||
} else {}
|
||||
} else {}
|
||||
}
|
||||
|
||||
Future getTextFromCard(String prompt) async {
|
||||
@@ -1133,7 +1015,6 @@ Output the extracted information in the following JSON formate and make date for
|
||||
},
|
||||
],
|
||||
});
|
||||
print(requestBody);
|
||||
|
||||
final response = await http.post(
|
||||
Uri.parse(
|
||||
@@ -1146,13 +1027,9 @@ Output the extracted information in the following JSON formate and make date for
|
||||
if (response.statusCode == 200) {
|
||||
var responseData = jsonDecode(response.body);
|
||||
// Process the responseData as needed
|
||||
// print(responseData);
|
||||
|
||||
var result =
|
||||
responseData['candidates'][0]['content']['parts'][0]['text'];
|
||||
// print(jsonEncode(result));
|
||||
// print((result));
|
||||
// print(result['dob']);
|
||||
RegExp regex = RegExp(r"```json([^`]*)```");
|
||||
String? jsonString =
|
||||
regex.firstMatch(responseData.toString())?.group(1)?.trim();
|
||||
@@ -1161,21 +1038,11 @@ Output the extracted information in the following JSON formate and make date for
|
||||
// Convert the JSON object to a String
|
||||
jsonString = jsonEncode(json.decode(jsonString));
|
||||
responseBackCarLicenseMap = jsonDecode(jsonString);
|
||||
// print(jsonString);
|
||||
print(responseBackCarLicenseMap);
|
||||
// print(responseCarLicenseMap['plate_number']);
|
||||
} else {
|
||||
print("JSON string not found");
|
||||
}
|
||||
} else {}
|
||||
|
||||
// Rest of your code...
|
||||
} else {
|
||||
print('Request failed with status: ${response.statusCode}');
|
||||
print('Request failed with status: ${response.body}');
|
||||
}
|
||||
} else {
|
||||
print('No image selected');
|
||||
}
|
||||
} else {}
|
||||
} else {}
|
||||
}
|
||||
|
||||
Future<void> generateBackCarLicenseJordanContent() async {
|
||||
@@ -1229,7 +1096,6 @@ Output the extracted information in the following JSON formate and make date for
|
||||
},
|
||||
],
|
||||
});
|
||||
print(requestBody);
|
||||
|
||||
final response = await http.post(
|
||||
Uri.parse(
|
||||
@@ -1242,13 +1108,9 @@ Output the extracted information in the following JSON formate and make date for
|
||||
if (response.statusCode == 200) {
|
||||
var responseData = jsonDecode(response.body);
|
||||
// Process the responseData as needed
|
||||
// print(responseData);
|
||||
|
||||
var result =
|
||||
responseData['candidates'][0]['content']['parts'][0]['text'];
|
||||
// print(jsonEncode(result));
|
||||
// print((result));
|
||||
// print(result['dob']);
|
||||
RegExp regex = RegExp(r"```json([^`]*)```");
|
||||
String? jsonString =
|
||||
regex.firstMatch(responseData.toString())?.group(1)?.trim();
|
||||
@@ -1257,21 +1119,11 @@ Output the extracted information in the following JSON formate and make date for
|
||||
// Convert the JSON object to a String
|
||||
jsonString = jsonEncode(json.decode(jsonString));
|
||||
responseBackCarLicenseMap = jsonDecode(jsonString);
|
||||
// print(jsonString);
|
||||
print(responseBackCarLicenseMap);
|
||||
// print(responseCarLicenseMap['plate_number']);
|
||||
} else {
|
||||
print("JSON string not found");
|
||||
}
|
||||
} else {}
|
||||
|
||||
// Rest of your code...
|
||||
} else {
|
||||
print('Request failed with status: ${response.statusCode}');
|
||||
print('Request failed with status: ${response.body}');
|
||||
}
|
||||
} else {
|
||||
print('No image selected');
|
||||
}
|
||||
} else {}
|
||||
} else {}
|
||||
}
|
||||
|
||||
Future<void> getFromCarRegistration() async {
|
||||
@@ -1323,7 +1175,6 @@ Output the extracted information in the following JSON formate and make date for
|
||||
},
|
||||
],
|
||||
});
|
||||
print(requestBody);
|
||||
|
||||
final response = await http.post(
|
||||
Uri.parse(
|
||||
@@ -1337,7 +1188,6 @@ Output the extracted information in the following JSON formate and make date for
|
||||
// Process the responseData as needed
|
||||
var result =
|
||||
responseData['candidates'][0]['content']['parts'][0]['text'];
|
||||
print(result);
|
||||
RegExp regex = RegExp(r"```json([^`]*)```");
|
||||
String? jsonString =
|
||||
regex.firstMatch(responseData.toString())?.group(1)?.trim();
|
||||
@@ -1345,19 +1195,11 @@ Output the extracted information in the following JSON formate and make date for
|
||||
if (jsonString != null) {
|
||||
// Convert the JSON object to a String
|
||||
jsonString = jsonEncode(json.decode(jsonString));
|
||||
print(jsonString);
|
||||
} else {
|
||||
print("JSON string not found");
|
||||
}
|
||||
} else {}
|
||||
|
||||
// Rest of your code...
|
||||
} else {
|
||||
print('Request failed with status: ${response.statusCode}');
|
||||
print('Request failed with status: ${response.body}');
|
||||
}
|
||||
} else {
|
||||
print('No image selected');
|
||||
}
|
||||
} else {}
|
||||
} else {}
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user