5/2/passnew
This commit is contained in:
@@ -7,7 +7,6 @@ import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
import '../../constant/box_name.dart';
|
||||
import '../firebase/firbase_messge.dart';
|
||||
import '../home/captin/map_driver_controller.dart';
|
||||
import '../../main.dart';
|
||||
|
||||
class CallController extends GetxController {
|
||||
@@ -23,15 +22,15 @@ class CallController extends GetxController {
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
if (box.read(BoxName.passengerID) != null) {
|
||||
channelName = Get.find<MapPassengerController>().rideId; // 'sefer300'; //
|
||||
remoteUid = int.parse(Get.find<MapPassengerController>().driverPhone);
|
||||
uid = int.parse(box.read(BoxName.phone));
|
||||
} else {
|
||||
channelName = Get.find<MapDriverController>().rideId; // 'sefer300'; //
|
||||
remoteUid = int.parse(Get.find<MapDriverController>().passengerPhone);
|
||||
uid = int.parse(box.read(BoxName.phoneDriver));
|
||||
}
|
||||
// if (box.read(BoxName.passengerID) != null) {
|
||||
channelName = Get.find<MapPassengerController>().rideId; // 'sefer300'; //
|
||||
remoteUid = int.parse(Get.find<MapPassengerController>().driverPhone);
|
||||
uid = int.parse(box.read(BoxName.phone));
|
||||
// } else {
|
||||
// channelName = Get.find<MapDriverController>().rideId; // 'sefer300'; //
|
||||
// remoteUid = int.parse(Get.find<MapDriverController>().passengerPhone);
|
||||
// uid = int.parse(box.read(BoxName.phoneDriver));
|
||||
// }
|
||||
|
||||
initAgoraFull();
|
||||
}
|
||||
@@ -46,12 +45,8 @@ class CallController extends GetxController {
|
||||
// join();
|
||||
FirebaseMessagesController().sendNotificationToPassengerToken(
|
||||
'Call Income from Passenger',
|
||||
box.read(BoxName.passengerID) != null
|
||||
? '${'You have call from Passenger'.tr} ${box.read(BoxName.name)}'
|
||||
: '${'You have call from driver'.tr} ${box.read(BoxName.nameDriver)}',
|
||||
box.read(BoxName.passengerID) != null
|
||||
? Get.find<MapPassengerController>().driverToken
|
||||
: Get.find<MapDriverController>().tokenPassenger,
|
||||
'${'You have call from Passenger'.tr} ${box.read(BoxName.name)}',
|
||||
Get.find<MapPassengerController>().driverToken,
|
||||
[
|
||||
token,
|
||||
channelName,
|
||||
@@ -89,10 +84,8 @@ class CallController extends GetxController {
|
||||
},
|
||||
onUserJoined: (RtcConnection connection, int remoteUid, int elapsed) {
|
||||
// Get.snackbar("Remote user uid:$remoteUid joined the channel", '');
|
||||
status =
|
||||
'${box.read(BoxName.passengerID) != null ? Get.find<MapPassengerController>().driverName : Get.find<MapDriverController>().passengerName}'
|
||||
' joined'
|
||||
.tr;
|
||||
status = Get.find<MapPassengerController>().driverName.toString();
|
||||
' joined'.tr;
|
||||
remoteUid = remoteUid;
|
||||
update();
|
||||
},
|
||||
|
||||
@@ -1,245 +0,0 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:camera/camera.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:google_mlkit_text_recognition/google_mlkit_text_recognition.dart';
|
||||
import 'package:SEFER/constant/box_name.dart';
|
||||
import 'package:SEFER/constant/links.dart';
|
||||
import 'package:SEFER/views/widgets/elevated_btn.dart';
|
||||
import 'package:path_provider/path_provider.dart' as path_provider;
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:http/http.dart' as http;
|
||||
import '../../main.dart';
|
||||
|
||||
class CameraClassController extends GetxController {
|
||||
late CameraController cameraController;
|
||||
late List<CameraDescription> cameras;
|
||||
bool isCameraInitialized = false;
|
||||
final TextRecognizer _textRecognizer = TextRecognizer();
|
||||
String? scannedText;
|
||||
bool isloading = false;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
initializeCamera();
|
||||
}
|
||||
|
||||
Future<void> initializeCamera() async {
|
||||
try {
|
||||
cameras = await availableCameras();
|
||||
//update();
|
||||
cameraController = CameraController(
|
||||
cameras[0],
|
||||
ResolutionPreset.medium,
|
||||
enableAudio: false,
|
||||
);
|
||||
await cameraController.initialize();
|
||||
isCameraInitialized = true;
|
||||
update();
|
||||
} catch (e) {
|
||||
if (e is CameraException) {
|
||||
switch (e.code) {
|
||||
case 'CameraAccessDenied':
|
||||
Get.defaultDialog(
|
||||
title: 'Camera Access Denied.'.tr,
|
||||
middleText: '',
|
||||
confirm:
|
||||
MyElevatedButton(title: 'Open Settings'.tr, onPressed: () {}),
|
||||
);
|
||||
break;
|
||||
default:
|
||||
// Handle other errors here.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var imgUrl = '';
|
||||
Future extractCardId() async {
|
||||
// Construct the path for the image file
|
||||
final directory = await path_provider.getTemporaryDirectory();
|
||||
final imagePath =
|
||||
path.join(directory.path, '${box.read(BoxName.driverID)}.png');
|
||||
|
||||
// Capture the image and save it to the specified path
|
||||
final XFile capturedImage = await cameraController.takePicture();
|
||||
|
||||
// Move the captured image to the desired path
|
||||
await capturedImage.saveTo(imagePath);
|
||||
await uploadImage(File(capturedImage.path));
|
||||
|
||||
extractByAPI('${AppLink.server}/card_image/' + box.read(BoxName.driverID));
|
||||
}
|
||||
|
||||
Future extractByAPI(String imgUrl) async {
|
||||
var headers = {'apikey': 'K89368168788957'};
|
||||
var request = http.MultipartRequest(
|
||||
'POST', Uri.parse('https://api.ocr.space/parse/image'));
|
||||
request.fields.addAll({
|
||||
'language': 'ara',
|
||||
'isOverlayRequired': 'false',
|
||||
'url': imgUrl,
|
||||
'iscreatesearchablepdf': 'false',
|
||||
'issearchablepdfhidetextlayer': 'false'
|
||||
});
|
||||
|
||||
request.headers.addAll(headers);
|
||||
|
||||
http.StreamedResponse response = await request.send();
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
print(await response.stream.bytesToString());
|
||||
} else {
|
||||
print(response.reasonPhrase);
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> uploadImage(File imageFile) async {
|
||||
String? basicAuthCredentials =
|
||||
await storage.read(key: BoxName.basicAuthCredentials);
|
||||
var request = http.MultipartRequest(
|
||||
'POST',
|
||||
Uri.parse(AppLink.uploadImage),
|
||||
);
|
||||
|
||||
// Attach the image file to the request
|
||||
request.files.add(
|
||||
await http.MultipartFile.fromPath('image', imageFile.path),
|
||||
); // Add the headers to the request
|
||||
request.headers.addAll({
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
'Authorization':
|
||||
'Basic ${base64Encode(utf8.encode(basicAuthCredentials.toString()))}',
|
||||
});
|
||||
|
||||
// Add the driverID to the request
|
||||
request.fields['driverID'] = box.read(BoxName.driverID);
|
||||
// Send the request
|
||||
var response = await request.send();
|
||||
|
||||
// Read the response
|
||||
var responseData = await response.stream.toBytes();
|
||||
var responseString = String.fromCharCodes(responseData);
|
||||
scannedText = responseString;
|
||||
update();
|
||||
// Return the link received from the server
|
||||
return responseString;
|
||||
}
|
||||
|
||||
Future<void> takePictureAndMLGoogleScan() async {
|
||||
try {
|
||||
// Construct the path for the image file
|
||||
final directory = await path_provider.getTemporaryDirectory();
|
||||
final imagePath =
|
||||
path.join(directory.path, '${box.read(BoxName.driverID)}.png');
|
||||
|
||||
// Capture the image and save it to the specified path
|
||||
final XFile capturedImage = await cameraController.takePicture();
|
||||
|
||||
// Move the captured image to the desired path
|
||||
await capturedImage.saveTo(imagePath);
|
||||
|
||||
// Recognize the text in the image
|
||||
final InputImage inputImage =
|
||||
InputImage.fromFile(File(capturedImage.path));
|
||||
final RecognizedText recognizedText =
|
||||
await _textRecognizer.processImage(inputImage);
|
||||
scannedText = recognizedText.text;
|
||||
|
||||
// Extract the scanned text line by line
|
||||
final List<Map<String, dynamic>> lines = [];
|
||||
for (var i = 0; i < recognizedText.blocks.length; i++) {
|
||||
lines.add({
|
||||
'line_number': i,
|
||||
'text': recognizedText.blocks[i].text,
|
||||
});
|
||||
}
|
||||
|
||||
// Convert the list of lines to a JSON string
|
||||
final String jsonOutput = jsonEncode(lines);
|
||||
|
||||
update();
|
||||
|
||||
// Print the JSON output
|
||||
print(jsonOutput);
|
||||
|
||||
// Get.back();
|
||||
} catch (e) {
|
||||
print('Error capturing image: $e');
|
||||
}
|
||||
}
|
||||
|
||||
String getTextAsJSON(String text) {
|
||||
final lines = text.split('\n');
|
||||
final jsonList = lines.map((line) {
|
||||
return {
|
||||
'line_text': line,
|
||||
'num_words': line.trim().split(' ').length,
|
||||
};
|
||||
}).toList();
|
||||
|
||||
final json = {
|
||||
'lines': jsonList,
|
||||
'num_lines': lines.length,
|
||||
};
|
||||
|
||||
return jsonEncode(json);
|
||||
}
|
||||
|
||||
List<String> getTextBlocks(String text) {
|
||||
return text.split('\n');
|
||||
}
|
||||
|
||||
// Future<void> takePictureAndTesseractScan() async {
|
||||
// try {
|
||||
// // Construct the path for the image file
|
||||
// final directory = await path_provider.getTemporaryDirectory();
|
||||
// final imagePath =
|
||||
// path.join(directory.path, '${box.read(BoxName.driverID)}.png');
|
||||
|
||||
// // Capture the image and save it to the specified path
|
||||
// final XFile capturedImage = await cameraController.takePicture();
|
||||
|
||||
// // Move the captured image to the desired path
|
||||
// await capturedImage.saveTo(imagePath);
|
||||
|
||||
// // Recognize the text in the image
|
||||
// final languages = [
|
||||
// 'eng',
|
||||
// 'ara'
|
||||
// ]; // Specify the languages you want to use for text extraction
|
||||
|
||||
// final text = await FlutterTesseractOcr.extractText(imagePath,
|
||||
// language: languages.join('+'), // Combine multiple languages with '+'
|
||||
// args: {
|
||||
// "psm": "4",
|
||||
// "preserve_interword_spaces": "1",
|
||||
// // "rectangle": const Rect.fromLTWH(100, 100, 200, 200),
|
||||
// } // Additional options if needed
|
||||
// );
|
||||
// isloading = false;
|
||||
// final jsonText = getTextAsJSON(text);
|
||||
// final textBlocks = getTextBlocks(text);
|
||||
// update();
|
||||
// scannedText =
|
||||
// textBlocks.toString(); // Convert the extracted text to JSON.
|
||||
|
||||
// // Print the JSON to the console.
|
||||
// print(jsonText);
|
||||
// update();
|
||||
// // print(text);
|
||||
// } catch (e) {
|
||||
// print('Error during text extraction: $e');
|
||||
// scannedText = '';
|
||||
// }
|
||||
// }
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
cameraController.dispose();
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,7 @@ import 'package:http/http.dart' as http;
|
||||
import 'package:SEFER/env/env.dart';
|
||||
|
||||
import '../../constant/api_key.dart';
|
||||
import 'gemeni.dart';
|
||||
import 'llama_ai.dart';
|
||||
|
||||
import 'upload_image.dart';
|
||||
|
||||
class CRUD {
|
||||
@@ -106,7 +105,7 @@ class CRUD {
|
||||
Future.delayed(const Duration(seconds: 2));
|
||||
String extracted =
|
||||
await arabicTextExtractByVisionAndAI(imagePath: imagePath);
|
||||
await AI().geminiAiExtraction(prompt, extracted);
|
||||
// await AI().geminiAiExtraction(prompt, extracted);
|
||||
}
|
||||
|
||||
Future<dynamic> arabicTextExtractByVisionAndAI({
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
// import 'dart:io';
|
||||
//
|
||||
// import 'package:get/get.dart';
|
||||
// import 'package:image_picker/image_picker.dart';
|
||||
// import 'package:google_ml_kit/google_ml_kit.dart';
|
||||
//
|
||||
// class ImagePickerController extends GetxController {
|
||||
// RxBool textScanning = false.obs;
|
||||
// RxString scannedText = ''.obs;
|
||||
//
|
||||
// Future<void> getImage(ImageSource source) async {
|
||||
// try {
|
||||
// final pickedImage = await ImagePicker().pickImage(source: source);
|
||||
// if (pickedImage != null) {
|
||||
// textScanning.value = true;
|
||||
// final imageFile = File(pickedImage.path);
|
||||
// getRecognisedText(imageFile);
|
||||
// }
|
||||
// } catch (e) {
|
||||
// textScanning.value = false;
|
||||
// scannedText.value = "Error occurred while scanning";
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Future<void> getRecognisedText(File image) async {
|
||||
// final inputImage = InputImage.fromFilePath(image.path);
|
||||
// final textDetector = GoogleMlKit.vision.textRecognizer();
|
||||
// final RecognizedText recognisedText =
|
||||
// await textDetector.processImage(inputImage);
|
||||
// await textDetector.close();
|
||||
//
|
||||
// scannedText.value = '';
|
||||
// for (TextBlock block in recognisedText.blocks) {
|
||||
// for (TextLine line in block.lines) {
|
||||
// scannedText.value += line.text + '\n';
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// textScanning.value = false;
|
||||
// }
|
||||
// }
|
||||
@@ -1,928 +0,0 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
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';
|
||||
|
||||
class AI 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);
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
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',
|
||||
},
|
||||
],
|
||||
});
|
||||
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,
|
||||
);
|
||||
|
||||
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));
|
||||
print(jsonString);
|
||||
} 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> geminiAiExtraction(String prompt, payload) async {
|
||||
var requestBody = jsonEncode({
|
||||
'contents': [
|
||||
{
|
||||
'parts': [
|
||||
// {
|
||||
// 'inlineData': {
|
||||
// 'mimeType': 'image/jpeg',
|
||||
// 'data': imageData,
|
||||
// },
|
||||
// },
|
||||
{
|
||||
'text':
|
||||
"Extract the desired information from the following passage as json decoded like $prompt just in this:\n\n$payload"
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
'generationConfig': {
|
||||
'temperature': 0.4,
|
||||
'topK': 32,
|
||||
'topP': 1,
|
||||
'maxOutputTokens': 4096,
|
||||
'stopSequences': [],
|
||||
},
|
||||
'safety_settings': [
|
||||
{"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_NONE"},
|
||||
{"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_NONE"},
|
||||
{
|
||||
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
||||
"threshold": "BLOCK_NONE"
|
||||
},
|
||||
{
|
||||
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
|
||||
"threshold": "BLOCK_NONE"
|
||||
},
|
||||
]
|
||||
});
|
||||
print(requestBody);
|
||||
|
||||
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=AIzaSyCyoLcSkDzK5_SMe00nhut56SSXWPR074w'),
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: requestBody,
|
||||
);
|
||||
|
||||
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));
|
||||
print(jsonString);
|
||||
} 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}');
|
||||
}
|
||||
}
|
||||
|
||||
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',
|
||||
},
|
||||
],
|
||||
});
|
||||
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> 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',
|
||||
},
|
||||
],
|
||||
});
|
||||
print(requestBody);
|
||||
|
||||
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
|
||||
// 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> 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',
|
||||
},
|
||||
],
|
||||
});
|
||||
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> 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',
|
||||
},
|
||||
],
|
||||
});
|
||||
print(requestBody);
|
||||
|
||||
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
|
||||
// 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 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',
|
||||
},
|
||||
],
|
||||
});
|
||||
print(requestBody);
|
||||
|
||||
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
|
||||
// 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> 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) {
|
||||
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',
|
||||
},
|
||||
],
|
||||
});
|
||||
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,
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
var responseData = jsonDecode(response.body);
|
||||
// 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();
|
||||
|
||||
if (jsonString != null) {
|
||||
// Convert the JSON object to a String
|
||||
jsonString = jsonEncode(json.decode(jsonString));
|
||||
print(jsonString);
|
||||
} 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');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
// generateContent();
|
||||
super.onInit();
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:SEFER/constant/links.dart';
|
||||
import 'package:SEFER/controller/functions/crud.dart';
|
||||
import 'package:SEFER/controller/functions/gemeni.dart';
|
||||
|
||||
class LlamaAi {
|
||||
Future<Map> getCarRegistrationData(String input, prompt) async {
|
||||
print(true);
|
||||
Map exrtatDataFinal = {};
|
||||
String oneLine = input.replaceAll('\n', ' ');
|
||||
// print(oneLine);
|
||||
// var res = await CRUD().getLlama(link: AppLink.gemini, payload: oneLine);
|
||||
var res = await CRUD()
|
||||
.getLlama(link: AppLink.llama, payload: oneLine, prompt: prompt);
|
||||
|
||||
print(res);
|
||||
var decod = jsonDecode(res.toString());
|
||||
print(decod);
|
||||
// exrtatDataFinal = jsonDecode(extractDataFromJsonString(decod['choices']));
|
||||
extractDataFromJsonString(decod['choices'][0]['message']['content']);
|
||||
print(jsonEncode(exrtatDataFinal));
|
||||
print(false);
|
||||
return exrtatDataFinal;
|
||||
}
|
||||
|
||||
String extractDataFromJsonString(String jsonString) {
|
||||
// Remove any leading or trailing whitespace from the string
|
||||
jsonString = jsonString.trim();
|
||||
|
||||
// Extract the JSON substring from the given string
|
||||
final startIndex = jsonString.indexOf('{');
|
||||
final endIndex = jsonString.lastIndexOf('}');
|
||||
final jsonSubstring = jsonString.substring(startIndex, endIndex + 1);
|
||||
|
||||
// Parse the JSON substring into a Map
|
||||
final jsonData = jsonDecode(jsonSubstring);
|
||||
|
||||
// Return the extracted data
|
||||
|
||||
// print(jsonEncode(jsonData));
|
||||
return jsonEncode(jsonData);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:SEFER/controller/home/captin/home_captain_controller.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
import 'package:location/location.dart';
|
||||
@@ -10,8 +9,6 @@ import 'package:SEFER/controller/functions/crud.dart';
|
||||
import 'package:SEFER/controller/home/payment/captain_wallet_controller.dart';
|
||||
import 'package:SEFER/main.dart';
|
||||
|
||||
import '../home/captin/map_driver_controller.dart';
|
||||
|
||||
// LocationController.dart
|
||||
class LocationController extends GetxController {
|
||||
LocationData? _currentLocation;
|
||||
@@ -71,39 +68,6 @@ class LocationController extends GetxController {
|
||||
: totalDistance.toStringAsFixed(1),
|
||||
'status': box.read(BoxName.statusDriverLocation).toString()
|
||||
});
|
||||
// Animate camera to user location (optional)
|
||||
// if (Get.find<HomeCaptainController>().rideId == 'rideId') {
|
||||
// Get.find<MapDriverController>()
|
||||
// .mapController!
|
||||
// .animateCamera(CameraUpdate.newLatLng(LatLng(
|
||||
// Get.find<LocationController>().myLocation.latitude,
|
||||
// Get.find<LocationController>().myLocation.longitude,
|
||||
// )));
|
||||
// }
|
||||
Get.find<HomeCaptainController>()
|
||||
.mapHomeCaptainController
|
||||
.animateCamera(CameraUpdate.newLatLng(LatLng(
|
||||
Get.find<LocationController>().myLocation.latitude,
|
||||
Get.find<LocationController>().myLocation.longitude,
|
||||
)));
|
||||
// if (Get.find<HomeCaptainController>().rideId == '0') {
|
||||
// await sql.insertData({
|
||||
// 'driver_id': box.read(BoxName.driverID),
|
||||
// 'latitude': myLocation.latitude.toString(),
|
||||
// 'longitude': myLocation.longitude.toString(),
|
||||
// 'created_at': DateTime.now().toString(),
|
||||
// }, TableName.carLocations);
|
||||
// } else {
|
||||
// await sql.insertData({
|
||||
// 'order_id': Get.find<MapDriverController>().rideId,
|
||||
// 'created_at': DateTime.now().toString(),
|
||||
// 'lat': myLocation.latitude.toString(),
|
||||
// 'lng': myLocation.longitude.toString(),
|
||||
// }, TableName.rideLocation);
|
||||
// }
|
||||
// }
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
// }
|
||||
@@ -157,17 +121,17 @@ class LocationController extends GetxController {
|
||||
speed = _locationData.speed!;
|
||||
heading = _locationData.heading!;
|
||||
// Calculate the distance between the current location and the previous location
|
||||
if (Get.find<HomeCaptainController>().rideId == 'rideId') {
|
||||
if (previousTime > 0) {
|
||||
double distance = calculateDistanceInKmPerHour(
|
||||
previousTime, _locationData.time, speed);
|
||||
print('distance $distance');
|
||||
totalDistance += distance;
|
||||
}
|
||||
// print('totalDistance: $totalDistance');
|
||||
// if (Get.find<HomeCaptainController>().rideId == 'rideId') {
|
||||
// if (previousTime > 0) {
|
||||
// double distance = calculateDistanceInKmPerHour(
|
||||
// previousTime, _locationData.time, speed);
|
||||
// print('distance $distance');
|
||||
// totalDistance += distance;
|
||||
// }
|
||||
// // print('totalDistance: $totalDistance');
|
||||
|
||||
previousTime = _locationData.time!;
|
||||
}
|
||||
// previousTime = _locationData.time!;
|
||||
// }
|
||||
// Print location details
|
||||
// print('myLocation: ${myLocation}');
|
||||
// print('Accuracy: ${_locationData.accuracy}');
|
||||
|
||||
@@ -1,673 +0,0 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
import 'package:camera/camera.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:SEFER/constant/api_key.dart';
|
||||
import 'package:SEFER/constant/colors.dart';
|
||||
import 'package:SEFER/constant/info.dart';
|
||||
import 'package:SEFER/constant/style.dart';
|
||||
import 'package:SEFER/constant/table_names.dart';
|
||||
import 'package:SEFER/main.dart';
|
||||
import 'package:SEFER/views/widgets/elevated_btn.dart';
|
||||
|
||||
import '../../constant/box_name.dart';
|
||||
import '../../constant/links.dart';
|
||||
import '../auth/captin/register_captin_controller.dart';
|
||||
import 'launch.dart';
|
||||
|
||||
//
|
||||
// class TextExtractionController extends GetxController {
|
||||
// String extractedText = '';
|
||||
// bool isloading = false;
|
||||
// File? _scannedImage;
|
||||
// // Convert the extracted text to JSON
|
||||
// // Convert the extracted text to JSON
|
||||
// String getTextAsJSON(String text) {
|
||||
// final lines = text.split('\n');
|
||||
// final jsonList = lines.map((line) {
|
||||
// return {
|
||||
// 'line_text': line,
|
||||
// 'num_words': line.trim().split(' ').length,
|
||||
// };
|
||||
// }).toList();
|
||||
//
|
||||
// final json = {
|
||||
// 'lines': jsonList,
|
||||
// 'num_lines': lines.length,
|
||||
// };
|
||||
//
|
||||
// return jsonEncode(json);
|
||||
// }
|
||||
//
|
||||
// // Convert the extracted text to blocks by line
|
||||
// List<String> getTextBlocks(String text) {
|
||||
// return text.split('\n');
|
||||
// }
|
||||
//
|
||||
// // Future<void> pickAndExtractText() async {
|
||||
// // final pickedImage = await ImagePicker().pickImage(
|
||||
// // source: ImageSource.camera,
|
||||
// // preferredCameraDevice: CameraDevice.rear,
|
||||
// // maxHeight: Get.height * .3,
|
||||
// // maxWidth: Get.width * .8,
|
||||
// // imageQuality: 99,
|
||||
// // );
|
||||
// // if (pickedImage != null) {
|
||||
// // isloading = true;
|
||||
// // update();
|
||||
// // final imagePath = pickedImage.path;
|
||||
// // final languages = [
|
||||
// // 'eng',
|
||||
// // 'ara'
|
||||
// // ]; // Specify the languages you want to use for text extraction
|
||||
//
|
||||
// // try {
|
||||
// // final text = await FlutterTesseractOcr.extractText(imagePath,
|
||||
// // language:
|
||||
// // languages.join('+'), // Combine multiple languages with '+'
|
||||
// // args: {
|
||||
// // "psm": "4",
|
||||
// // "preserve_interword_spaces": "1",
|
||||
// // // "rectangle": const Rect.fromLTWH(100, 100, 200, 200),
|
||||
// // } // Additional options if needed
|
||||
// // );
|
||||
// // isloading = false;
|
||||
// // final jsonText = getTextAsJSON(text);
|
||||
// // final textBlocks = getTextBlocks(text);
|
||||
// // update();
|
||||
// // extractedText =
|
||||
// // textBlocks.toString(); // Convert the extracted text to JSON.
|
||||
//
|
||||
// // // Print the JSON to the console.
|
||||
// // print(jsonText);
|
||||
// // update();
|
||||
// // // print(text);
|
||||
// // } catch (e) {
|
||||
// // print('Error during text extraction: $e');
|
||||
// // extractedText = '';
|
||||
// // }
|
||||
// // }
|
||||
// // }
|
||||
// }
|
||||
|
||||
// class TextMLGoogleRecognizerController extends GetxController {
|
||||
// @override
|
||||
// void onInit() {
|
||||
// scanText();
|
||||
// super.onInit();
|
||||
// }
|
||||
//
|
||||
// // The ImagePicker instance
|
||||
// final ImagePicker _imagePicker = ImagePicker();
|
||||
//
|
||||
// // The GoogleMlKit TextRecognizer instance
|
||||
// final TextRecognizer _textRecognizer = TextRecognizer();
|
||||
//
|
||||
// // The scanned text
|
||||
// String? scannedText;
|
||||
// String? jsonOutput;
|
||||
// final List<Map<String, dynamic>> lines = [];
|
||||
//
|
||||
// Map decode = {};
|
||||
//
|
||||
// Future<void> scanText() async {
|
||||
// // Pick an image from the camera or gallery
|
||||
// final XFile? image =
|
||||
// await _imagePicker.pickImage(source: ImageSource.gallery);
|
||||
//
|
||||
// // If no image was picked, return
|
||||
// if (image == null) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // Convert the XFile object to an InputImage object
|
||||
// final InputImage inputImage = InputImage.fromFile(File(image.path));
|
||||
//
|
||||
// // Recognize the text in the image
|
||||
// final RecognizedText recognizedText =
|
||||
// await _textRecognizer.processImage(inputImage);
|
||||
// scannedText = recognizedText.text;
|
||||
// Map extractedData = {};
|
||||
// // Extract the scanned text line by line
|
||||
// for (var i = 0; i < recognizedText.blocks.length; i++) {
|
||||
// final block = recognizedText.blocks[i];
|
||||
// for (final line in block.lines) {
|
||||
// final lineText = line.text;
|
||||
//
|
||||
// if (lineText.contains('DL')) {
|
||||
// final dlNumber = lineText.split('DL')[1].trim();
|
||||
// extractedData['dl_number'] = dlNumber;
|
||||
// }
|
||||
// if (lineText.contains('USA')) {
|
||||
// final usa = lineText.split('USA')[1].trim();
|
||||
// extractedData['USA'] = usa;
|
||||
// }
|
||||
// if (lineText.contains('DRIVER LICENSE')) {
|
||||
// final driverl = lineText;
|
||||
// extractedData['DRIVER_LICENSE'] = driverl;
|
||||
// }
|
||||
//
|
||||
// if (lineText.contains('EXP')) {
|
||||
// final expiryDate = lineText.split('EXP')[1].trim();
|
||||
// extractedData['expiry_date'] = expiryDate;
|
||||
// }
|
||||
//
|
||||
// if (lineText.contains('DOB')) {
|
||||
// final dob = lineText.split('DOB')[1].trim();
|
||||
// extractedData['dob'] = dob;
|
||||
// }
|
||||
//
|
||||
// if (lineText.contains("LN")) {
|
||||
// if ((lineText.indexOf("LN") == 0)) {
|
||||
// final lastName = lineText.split('LN')[1].trim();
|
||||
// extractedData['lastName'] = lastName;
|
||||
// }
|
||||
// }
|
||||
// if (lineText.contains("FN")) {
|
||||
// final firstName = lineText.split('FN')[1].trim();
|
||||
// extractedData['firstName'] = firstName;
|
||||
// }
|
||||
// if (lineText.contains("RSTR")) {
|
||||
// final rstr = lineText.split('RSTR')[1].trim();
|
||||
// extractedData['rstr'] = rstr;
|
||||
// }
|
||||
// if (lineText.contains("CLASS")) {
|
||||
// final class1 = lineText.split('CLASS')[1].trim();
|
||||
// extractedData['class'] = class1;
|
||||
// }
|
||||
// if (lineText.contains("END")) {
|
||||
// final end = lineText.split('END')[1].trim();
|
||||
// extractedData['end'] = end;
|
||||
// }
|
||||
// if (lineText.contains("DD")) {
|
||||
// final dd = lineText.split('DD')[1].trim();
|
||||
// extractedData['dd'] = dd;
|
||||
// }
|
||||
// if (lineText.contains("EYES")) {
|
||||
// final eyes = lineText.split('EYES')[1].trim();
|
||||
// extractedData['eyes'] = eyes;
|
||||
// }
|
||||
// if (lineText.contains("SEX")) {
|
||||
// final parts = lineText.split("SEX ")[1];
|
||||
// extractedData['sex'] = parts[0];
|
||||
// }
|
||||
// if (lineText.contains("HAIR")) {
|
||||
// final hair = lineText.split('HAIR')[1].trim();
|
||||
// extractedData['hair'] = hair;
|
||||
// }
|
||||
//
|
||||
// if (lineText.contains('STREET') || lineText.contains(',')) {
|
||||
// final address = lineText;
|
||||
// extractedData['address'] = address;
|
||||
// }
|
||||
//
|
||||
// // Repeat this process for other relevant data fields
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Convert the list of lines to a JSON string
|
||||
// jsonOutput = jsonEncode(extractedData);
|
||||
// decode = jsonDecode(jsonOutput!);
|
||||
//
|
||||
// update();
|
||||
// print('jsonOutput------------------------------');
|
||||
// print(scannedText);
|
||||
// }
|
||||
// }
|
||||
|
||||
class ScanDocumentsByApi extends GetxController {
|
||||
bool isLoading = false;
|
||||
Map<String, dynamic> responseMap = {};
|
||||
final ImagePicker imagePicker = ImagePicker();
|
||||
late Uint8List imagePortrait;
|
||||
late Uint8List imageSignature;
|
||||
late Uint8List imageDocumentFrontSide;
|
||||
XFile? image;
|
||||
XFile? imagePortraitFile;
|
||||
XFile? imageFace;
|
||||
late File tempFile;
|
||||
late String imagePath;
|
||||
DateTime now = DateTime.now();
|
||||
late String name;
|
||||
late String licenseClass;
|
||||
late String documentNo;
|
||||
late String address;
|
||||
late String stateCode;
|
||||
late String height;
|
||||
late String sex;
|
||||
late String postalCode;
|
||||
late String dob;
|
||||
late String expireDate;
|
||||
|
||||
// ///////////////////////
|
||||
// late CameraController cameraController;
|
||||
// late List<CameraDescription> cameras;
|
||||
// bool isCameraInitialized = false;
|
||||
// // final TextRecognizer _textRecognizer = TextRecognizer();
|
||||
// String? scannedText;
|
||||
|
||||
// Future<void> initializeCamera(int cameraID) async {
|
||||
// try {
|
||||
// cameras = await availableCameras();
|
||||
// //update();
|
||||
// cameraController = CameraController(
|
||||
// cameras[cameraID],
|
||||
// ResolutionPreset.medium,
|
||||
// enableAudio: false,
|
||||
// );
|
||||
// await cameraController.initialize();
|
||||
// isCameraInitialized = true;
|
||||
// update();
|
||||
// } catch (e) {
|
||||
// if (e is CameraException) {
|
||||
// switch (e.code) {
|
||||
// case 'CameraAccessDenied':
|
||||
// Get.defaultDialog(
|
||||
// title: 'Camera Access Denied.'.tr,
|
||||
// middleText: '',
|
||||
// confirm:
|
||||
// MyElevatedButton(title: 'Open Settings', onPressed: () {}),
|
||||
// );
|
||||
// break;
|
||||
// default:
|
||||
// // Handle other errors here.
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
///
|
||||
|
||||
Future<void> scanDocumentsByApi() async {
|
||||
// String? visionApi = await storage.read(key: BoxName.visionApi);
|
||||
// String? visionApi = AK.visionApi;
|
||||
// Pick an image from the camera or gallery
|
||||
// print(visionApi);
|
||||
image = await imagePicker.pickImage(source: ImageSource.camera); //
|
||||
|
||||
// If no image was picked, return
|
||||
if (image == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
isLoading = true;
|
||||
update();
|
||||
var headers = {'X-BLOBR-KEY': AK.visionApi};
|
||||
var request = http.MultipartRequest('POST',
|
||||
Uri.parse('https://api.faceonlive.com/j2y3q25y1b6maif1/api/iddoc'));
|
||||
request.files.add(await http.MultipartFile.fromPath('image', image!.path));
|
||||
request.headers.addAll(headers);
|
||||
|
||||
http.StreamedResponse response = await request.send();
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
String responseString = await response.stream.bytesToString();
|
||||
responseMap = jsonDecode(responseString);
|
||||
var ocrData = responseMap['data']['ocr'];
|
||||
name = ocrData['name'].toString();
|
||||
licenseClass = ocrData['dlClass'].toString();
|
||||
documentNo = ocrData['documentNumber'].toString();
|
||||
address = ocrData['address'].toString();
|
||||
height = ocrData['height'].toString();
|
||||
postalCode = ocrData['addressPostalCode'].toString();
|
||||
sex = ocrData['sex'].toString();
|
||||
stateCode = ocrData['addressJurisdictionCode'].toString();
|
||||
expireDate = ocrData['dateOfExpiry'].toString();
|
||||
dob = ocrData['dateOfBirth'].toString();
|
||||
if (responseMap['data'] != null &&
|
||||
responseMap['data']['image'] != null &&
|
||||
responseMap['data']['image']['portrait'] != null) {
|
||||
imagePortrait = base64Decode(responseMap['data']['image']['portrait']);
|
||||
String tempPath = Directory.systemTemp.path;
|
||||
tempFile = File('$tempPath/image.jpg');
|
||||
await tempFile.writeAsBytes(imagePortrait);
|
||||
|
||||
imagePath = tempFile.path;
|
||||
// imagePortraitFile=File(imagePath) ;
|
||||
update();
|
||||
} else {
|
||||
// Handle error or provide a default value
|
||||
}
|
||||
|
||||
if (responseMap['data']['image']['signature'] != null) {
|
||||
imageSignature =
|
||||
base64Decode(responseMap['data']['image']['signature']);
|
||||
} else {
|
||||
imageSignature = imagePortrait;
|
||||
// Handle error or provide a default value
|
||||
}
|
||||
|
||||
if (responseMap['data'] != null &&
|
||||
responseMap['data']['image'] != null &&
|
||||
responseMap['data']['image']['documentFrontSide'] != null) {
|
||||
imageDocumentFrontSide =
|
||||
base64Decode(responseMap['data']['image']['documentFrontSide']);
|
||||
} else {
|
||||
// Handle error or provide a default value
|
||||
}
|
||||
|
||||
// print(responseMap);
|
||||
isLoading = false;
|
||||
update();
|
||||
} else {
|
||||
print(response.reasonPhrase);
|
||||
}
|
||||
}
|
||||
|
||||
late int times;
|
||||
Future checkMatchFaceApi() async {
|
||||
sql.getAllData(TableName.faceDetectTimes).then((value) {
|
||||
if (value.isEmpty || value == null) {
|
||||
sql.insertData({'faceDetectTimes': 1}, TableName.faceDetectTimes);
|
||||
sql.getAllData(TableName.faceDetectTimes).then((value) {
|
||||
times = value[0]['faceDetectTimes'];
|
||||
update();
|
||||
});
|
||||
} else {
|
||||
if (times < 4) {
|
||||
times++;
|
||||
matchFaceApi();
|
||||
sql.updateData(
|
||||
{'faceDetectTimes': times}, TableName.faceDetectTimes, 1);
|
||||
} else {
|
||||
Get.defaultDialog(
|
||||
barrierDismissible: false,
|
||||
title: 'You have finished all times '.tr,
|
||||
titleStyle: AppStyle.title,
|
||||
middleText: 'if you want help you can email us here'.tr,
|
||||
middleTextStyle: AppStyle.title,
|
||||
cancel: MyElevatedButton(
|
||||
title: 'Thanks'.tr,
|
||||
kolor: AppColor.greenColor,
|
||||
onPressed: () => Get.back(),
|
||||
),
|
||||
confirm: MyElevatedButton(
|
||||
title: 'Email Us'.tr,
|
||||
kolor: AppColor.yellowColor, //
|
||||
onPressed: () {
|
||||
launchCommunication('email', 'support@mobile-app.store',
|
||||
'${'Hi'.tr} ${AppInformation.appName}\n${'I cant register in your app in face detection '.tr}');
|
||||
Get.back();
|
||||
},
|
||||
));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Map res = {};
|
||||
Future matchFaceApi() async {
|
||||
// String? visionApi = await storage.read(key: BoxName.visionApi);
|
||||
imageFace = await imagePicker.pickImage(
|
||||
source: ImageSource.camera,
|
||||
preferredCameraDevice: CameraDevice.front,
|
||||
);
|
||||
|
||||
// If no image was picked, return
|
||||
if (image == null) {
|
||||
return;
|
||||
}
|
||||
final imageFile = File(imageFace!.path);
|
||||
// Uint8List imageBytes = await imageFile.readAsBytes();
|
||||
var headers = {'X-BLOBR-KEY': AK.visionApi};
|
||||
var request = http.MultipartRequest(
|
||||
'POST',
|
||||
Uri.parse(
|
||||
'https://api.faceonlive.com/sntzbspfsdupgid1/api/face_compare'));
|
||||
request.files
|
||||
.add(await http.MultipartFile.fromPath('image1', imageFile.path));
|
||||
request.files.add(await http.MultipartFile.fromPath('image2', imagePath));
|
||||
request.headers.addAll(headers);
|
||||
|
||||
http.StreamedResponse response = await request.send();
|
||||
print('Request: ${request.toString()}');
|
||||
print('Response Status Code: ${response.statusCode}');
|
||||
print('Response Reason Phrase: ${response.reasonPhrase}');
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
res = jsonDecode(await response.stream.bytesToString());
|
||||
print(res);
|
||||
|
||||
update();
|
||||
res['data']['result'].toString().contains('No face detected in image')
|
||||
? Get.defaultDialog(
|
||||
barrierDismissible: false,
|
||||
title: 'No face detected'.tr,
|
||||
middleText: ''.tr,
|
||||
titleStyle: AppStyle.title,
|
||||
confirm: MyElevatedButton(
|
||||
kolor: AppColor.yellowColor,
|
||||
title: 'Back'.tr,
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
},
|
||||
)) //
|
||||
: Get.defaultDialog(
|
||||
// barrierDismissible: false,
|
||||
title: 'Image detecting result is '.tr,
|
||||
titleStyle: AppStyle.title,
|
||||
content: Column(
|
||||
children: [
|
||||
Text(
|
||||
res['data']['result'].toString(),
|
||||
style: res['data']['result'].toString() == 'Different'
|
||||
? AppStyle.title.copyWith(color: AppColor.redColor)
|
||||
: AppStyle.title.copyWith(color: AppColor.greenColor),
|
||||
),
|
||||
res['data']['result'].toString() == 'Different'
|
||||
? Text(
|
||||
'${'Be sure for take accurate images please\nYou have'.tr} $times ${'from 3 times Take Attention'.tr}',
|
||||
style: AppStyle.title,
|
||||
)
|
||||
: Text(
|
||||
'image verified'.tr,
|
||||
style: AppStyle.title,
|
||||
)
|
||||
],
|
||||
),
|
||||
confirm: res['data']['result'].toString() == 'Different'
|
||||
? MyElevatedButton(
|
||||
title: 'Back'.tr,
|
||||
onPressed: () => Get.back(),
|
||||
kolor: AppColor.redColor,
|
||||
)
|
||||
: MyElevatedButton(
|
||||
title: 'Next'.tr,
|
||||
onPressed: () async {
|
||||
RegisterCaptainController registerCaptainController =
|
||||
Get.put(RegisterCaptainController());
|
||||
|
||||
await registerCaptainController.register();
|
||||
await registerCaptainController.addLisence();
|
||||
await uploadImagePortrate();
|
||||
// Get.to(() => CarLicensePage());
|
||||
},
|
||||
// {
|
||||
// await uploadImage(
|
||||
// tempFile, AppLink.uploadImagePortrate);
|
||||
// Get.to(() => CarLicensePage());
|
||||
// },
|
||||
kolor: AppColor.greenColor,
|
||||
));
|
||||
} else {
|
||||
print(response.reasonPhrase);
|
||||
}
|
||||
}
|
||||
|
||||
// Todo upload images and fields
|
||||
Future<String> uploadImagePortrate() async {
|
||||
isLoading = true;
|
||||
update();
|
||||
|
||||
var request = http.MultipartRequest(
|
||||
'POST',
|
||||
Uri.parse(AppLink.uploadImagePortrate),
|
||||
);
|
||||
|
||||
request.files.add(
|
||||
http.MultipartFile.fromBytes('image', imagePortrait),
|
||||
);
|
||||
|
||||
request.headers.addAll({
|
||||
"Content-Type": "multipart/form-data",
|
||||
'Authorization':
|
||||
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials))}',
|
||||
});
|
||||
request.fields['driverID'] = box.read(BoxName.driverID).toString();
|
||||
|
||||
var response = await request.send();
|
||||
|
||||
var responseData = await response.stream.toBytes();
|
||||
var responseString = String.fromCharCodes(responseData);
|
||||
|
||||
isLoading = false;
|
||||
update();
|
||||
|
||||
// Print the response string
|
||||
print(responseString);
|
||||
|
||||
return responseString;
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
// scanDocumentsByApi();
|
||||
// initializeCamera(0);
|
||||
sql.getAllData(TableName.faceDetectTimes).then((value) {
|
||||
if (value.isEmpty) {
|
||||
print(value);
|
||||
times = 0;
|
||||
print(times);
|
||||
update();
|
||||
// sql.insertData({'faceDetectTimes': 1}, TableName.faceDetectTimes);
|
||||
} else {
|
||||
times = value[0]['faceDetectTimes'];
|
||||
}
|
||||
});
|
||||
super.onInit();
|
||||
}
|
||||
}
|
||||
|
||||
// class PassportDataExtractor extends GetxController {
|
||||
// @override
|
||||
// void onInit() {
|
||||
// extractPassportData();
|
||||
// super.onInit();
|
||||
// }
|
||||
//
|
||||
// final ImagePicker _imagePicker = ImagePicker();
|
||||
// late final XFile? image;
|
||||
// final TextRecognizer _textRecognizer = TextRecognizer();
|
||||
//
|
||||
// Future<Map<String, dynamic>> extractPassportData() async {
|
||||
// image = await _imagePicker.pickImage(source: ImageSource.gallery);
|
||||
// update();
|
||||
// if (image == null) {
|
||||
// throw Exception('No image picked');
|
||||
// }
|
||||
//
|
||||
// final InputImage inputImage = InputImage.fromFile(File(image!.path));
|
||||
// final RecognizedText recognisedText =
|
||||
// await _textRecognizer.processImage(inputImage);
|
||||
//
|
||||
// final Map<String, dynamic> extractedData = {};
|
||||
// final List<Map<String, dynamic>> extractedTextWithCoordinates = [];
|
||||
//
|
||||
// for (TextBlock block in recognisedText.blocks) {
|
||||
// for (TextLine line in block.lines) {
|
||||
// final String lineText = line.text;
|
||||
// final Rect lineBoundingBox = line.boundingBox!;
|
||||
//
|
||||
// extractedTextWithCoordinates.add({
|
||||
// 'text': lineText,
|
||||
// 'boundingBox': {
|
||||
// 'left': lineBoundingBox.left,
|
||||
// 'top': lineBoundingBox.top,
|
||||
// 'width': lineBoundingBox.width,
|
||||
// 'height': lineBoundingBox.height,
|
||||
// },
|
||||
// });
|
||||
//
|
||||
// // if (lineText.contains('Passport Number')) {
|
||||
// // final String passportNumber =
|
||||
// // lineText.split('Passport Number')[1].trim();
|
||||
// // extractedData['passportNumber'] = passportNumber;
|
||||
// // }
|
||||
// // if (lineText.contains('Given Names')) {
|
||||
// // final String givenNames = lineText.split('Given Names')[1].trim();
|
||||
// // extractedData['givenNames'] = givenNames;
|
||||
// // }
|
||||
// // if (lineText.contains('Surname')) {
|
||||
// // final String surname = lineText.split('Surname')[1].trim();
|
||||
// // extractedData['surname'] = surname;
|
||||
// // }
|
||||
// // if (lineText.contains('Nationality')) {
|
||||
// // final String nationality = lineText.split('Nationality')[1].trim();
|
||||
// // extractedData['nationality'] = nationality;
|
||||
// // }
|
||||
// // if (lineText.contains('Date of Birth')) {
|
||||
// // final String dob = lineText.split('Date of Birth')[1].trim();
|
||||
// // extractedData['dateOfBirth'] = dob;
|
||||
// // }
|
||||
// // Add more field extraction conditions as needed
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// extractedData['extractedTextWithCoordinates'] =
|
||||
// extractedTextWithCoordinates;
|
||||
// print(jsonEncode(extractedData));
|
||||
// return extractedData;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// class PassportDataController extends GetxController {
|
||||
// PassportDataExtractor passportDataExtractor = PassportDataExtractor();
|
||||
// List<Map<String, dynamic>> extractedTextWithCoordinates = [];
|
||||
//
|
||||
// Future<void> extractDataAndDrawBoundingBoxes() async {
|
||||
// try {
|
||||
// Map<String, dynamic> extractedData =
|
||||
// await passportDataExtractor.extractPassportData();
|
||||
// extractedTextWithCoordinates =
|
||||
// extractedData['extractedTextWithCoordinates'];
|
||||
// update(); // Notify GetX that the state has changed
|
||||
// print(extractedTextWithCoordinates);
|
||||
// } catch (e) {
|
||||
// print('Passport data extraction failed: $e');
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// class BoundingBoxPainter extends CustomPainter {
|
||||
// final List<Map<String, dynamic>> boundingBoxes;
|
||||
//
|
||||
// BoundingBoxPainter(this.boundingBoxes);
|
||||
//
|
||||
// @override
|
||||
// void paint(Canvas canvas, Size size) {
|
||||
// final Paint paint = Paint()
|
||||
// ..color = Colors.red
|
||||
// ..style = PaintingStyle.stroke
|
||||
// ..strokeWidth = 2.0;
|
||||
//
|
||||
// for (Map<String, dynamic> boundingBox in boundingBoxes) {
|
||||
// double left = boundingBox['left'];
|
||||
// double top = boundingBox['top'];
|
||||
// double width = boundingBox['width'];
|
||||
// double height = boundingBox['height'];
|
||||
//
|
||||
// Rect rect = Rect.fromLTWH(left, top, width, height);
|
||||
// canvas.drawRect(rect, paint);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @override
|
||||
// bool shouldRepaint(covariant CustomPainter oldDelegate) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
Reference in New Issue
Block a user