This commit is contained in:
Hamza-Ayed
2024-01-18 00:49:00 +03:00
parent 358bb904ab
commit 7af7e71b30
17 changed files with 1028 additions and 269 deletions

View File

@@ -12,10 +12,14 @@ import '../../constant/colors.dart';
class ContentController extends GetxController {
final picker = ImagePicker();
Map<String, dynamic> responseMap = {};
Map<String, dynamic> responseCarLicenseMap = {};
Map<String, dynamic> responseBackCarLicenseMap = {};
Map<String, dynamic> responseIdCardeMap = {};
bool isloading = false;
var image;
CroppedFile? croppedFile;
DateTime now = DateTime.now();
Future<void> pickImage() async {
final pickedImage = await picker.pickImage(source: ImageSource.gallery);
@@ -153,6 +157,294 @@ class ContentController extends GetxController {
}
}
Future<void> generateDriverLicenseJordanContent() 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',
},
],
});
print(requestBody);
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
// 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();
if (jsonString != null) {
// 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");
}
// Rest of your code...
} else {
print('Request failed with status: ${response.statusCode}');
print('Request failed with status: ${response.body}');
}
} else {
print('No image selected');
}
}
Future<void> generateCarLicenseJordanContent() 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 of this car license in jordan json contain name , address , car kind ,car color , car year , car plate ,registration adjective , using ,expire date of license and make date format like YYYY-MM-DD .dont add data else this image',
},
],
},
],
'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',
},
],
});
print(requestBody);
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
// 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();
if (jsonString != null) {
// Convert the JSON object to a String
jsonString = jsonEncode(json.decode(jsonString));
responseCarLicenseMap = jsonDecode(jsonString);
print(jsonString);
print(responseCarLicenseMap);
print(responseCarLicenseMap['plate_number']);
} else {
print("JSON string not found");
}
// Rest of your code...
} else {
print('Request failed with status: ${response.statusCode}');
print('Request failed with status: ${response.body}');
}
} else {
print('No image selected');
}
}
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',
},
],
});
print(requestBody);
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
// 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();
if (jsonString != null) {
// 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");
}
// Rest of your code...
} else {
print('Request failed with status: ${response.statusCode}');
print('Request failed with status: ${response.body}');
}
} else {
print('No image selected');
}
}
Future<void> getFromCarRegistration() async {
await pickImage();
if (image != null) {

View File

@@ -24,6 +24,7 @@ class LocationController extends GetxController {
void onInit() async {
super.onInit();
location = Location();
totalPoints = Get.find<CaptainWalletController>().totalPoints;
getLocation();
}