4/26/1
This commit is contained in:
@@ -91,7 +91,8 @@ class CarRegistrationRecognizerController extends GetxController {
|
||||
}
|
||||
// print('jsonOutput------------------------------');
|
||||
// print(result);
|
||||
Map result2 = await LlamaAi().getCarRegistrationData(result);
|
||||
Map result2 = await LlamaAi().getCarRegistrationData(result,
|
||||
'vin,make,made,year,expiration_date,color,owner,registration_date'); //
|
||||
|
||||
// Assign the result to the extracted variable
|
||||
extracted = result2;
|
||||
|
||||
@@ -776,7 +776,7 @@ class DriverTipWidget extends StatelessWidget {
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(6),
|
||||
child: Text(
|
||||
'${controller.totalPassenger * double.parse(box.read(BoxName.tipPercentage))} ${box.read(BoxName.countryCode) == 'Egypt' ? 'LE'.tr : 'JOD'.tr}',
|
||||
'${(controller.totalPassenger) * (double.parse(box.read(BoxName.tipPercentage.toString())))} ${box.read(BoxName.countryCode) == 'Egypt' ? 'LE'.tr : 'JOD'.tr}',
|
||||
style: AppStyle.title,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
import 'dart:convert';
|
||||
import 'package:SEFER/constant/box_name.dart';
|
||||
import 'package:SEFER/constant/links.dart';
|
||||
import 'package:SEFER/main.dart';
|
||||
import 'package:get/get.dart';
|
||||
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 {
|
||||
Future<dynamic> get({
|
||||
@@ -62,21 +66,25 @@ class CRUD {
|
||||
Future<dynamic> getLlama({
|
||||
required String link,
|
||||
required String payload,
|
||||
required String prompt,
|
||||
}) async {
|
||||
var url = Uri.parse(
|
||||
link,
|
||||
);
|
||||
var headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer ${Env.llamaKey}'
|
||||
'Authorization':
|
||||
'Bearer LL-X5lJ0Px9CzKK0HTuVZ3u2u4v3tGWkImLTG7okGRk4t25zrsLqJ0qNoUzZ2x4ciPy'
|
||||
// 'Authorization': 'Bearer ${Env.llamaKey}'
|
||||
};
|
||||
var data = json.encode({
|
||||
"model": "llama-13b-chat",
|
||||
"model": "Llama-3-70b-Inst-FW",
|
||||
// "model": "llama-13b-chat",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content":
|
||||
"Extract the desired information from the following passage as json decoded like vin,make,made,year,expiration_date,color,owner,registration_date just in this:\n\n$payload"
|
||||
"Extract the desired information from the following passage as json decoded like $prompt just in this:\n\n$payload"
|
||||
}
|
||||
],
|
||||
"temperature": 0.9
|
||||
@@ -93,6 +101,44 @@ class CRUD {
|
||||
return response.statusCode;
|
||||
}
|
||||
|
||||
Future allMethodForAI(String prompt, linkPHP, imagePath) async {
|
||||
await ImageController().choosImage(linkPHP, imagePath);
|
||||
Future.delayed(const Duration(seconds: 2));
|
||||
String extracted =
|
||||
await arabicTextExtractByVisionAndAI(imagePath: imagePath);
|
||||
await AI().geminiAiExtraction(prompt, extracted);
|
||||
}
|
||||
|
||||
Future<dynamic> arabicTextExtractByVisionAndAI({
|
||||
required String imagePath,
|
||||
}) async {
|
||||
var headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Ocp-Apim-Subscription-Key': '21010e54b50f41a4904708c526e102df'
|
||||
};
|
||||
var url = Uri.parse(
|
||||
'https://ocrhamza.cognitiveservices.azure.com/vision/v2.1/ocr?language=ar',
|
||||
);
|
||||
String imagePathFull =
|
||||
'${AppLink.server}card_image/$imagePath-${box.read(BoxName.driverID) ?? box.read(BoxName.passengerID)}.jpg';
|
||||
|
||||
print('imagePath=$imagePathFull');
|
||||
var requestBody = {"url": imagePathFull};
|
||||
var response = await http.post(
|
||||
url,
|
||||
body: jsonEncode(requestBody), // Encode the JSON object to a string
|
||||
headers: headers,
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
var responseBody = jsonDecode(response.body);
|
||||
// print(decode);
|
||||
print('imagePath=$imagePathFull');
|
||||
return responseBody.toString();
|
||||
}
|
||||
return response.statusCode;
|
||||
}
|
||||
|
||||
Future<dynamic> getChatGPT({
|
||||
required String link,
|
||||
required String payload,
|
||||
|
||||
@@ -158,6 +158,82 @@ class AI extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -2,19 +2,24 @@ 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) async {
|
||||
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);
|
||||
var decod = jsonDecode(res);
|
||||
// print(decod);
|
||||
exrtatDataFinal = jsonDecode(
|
||||
extractDataFromJsonString(decod['choices'][0]['message']['content']));
|
||||
// print(jsonEncode(exrtatDataFinal));
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,8 @@ class TextToSpeechController extends GetxController {
|
||||
Future<void> initTts() async {
|
||||
String? lang =
|
||||
WidgetsBinding.instance.platformDispatcher.locale.countryCode;
|
||||
await flutterTts.setLanguage(box.read(BoxName.lang)); //'en-US' Set language
|
||||
await flutterTts
|
||||
.setLanguage(box.read(BoxName.lang).toString()); //'en-US' Set language
|
||||
// await flutterTts.setLanguage('ar-SA'); //'en-US' Set language
|
||||
// await flutterTts.setLanguage(lang!); //'en-US' Set language
|
||||
await flutterTts.setSpeechRate(0.5); // Adjust speech rate
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'dart:io';
|
||||
import 'package:SEFER/constant/api_key.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:image_cropper/image_cropper.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:path/path.dart';
|
||||
|
||||
@@ -14,23 +15,56 @@ import '../../main.dart';
|
||||
class ImageController extends GetxController {
|
||||
File? myImage;
|
||||
bool isloading = false;
|
||||
void choosImage(String link) async {
|
||||
XFile? xFile = await ImagePicker().pickImage(source: ImageSource.gallery);
|
||||
myImage = File(xFile!.path);
|
||||
CroppedFile? croppedFile;
|
||||
final picker = ImagePicker();
|
||||
var image;
|
||||
choosImage(String link, String imageType) async {
|
||||
final pickedImage = await picker.pickImage(source: ImageSource.gallery);
|
||||
image = File(pickedImage!.path);
|
||||
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,
|
||||
),
|
||||
],
|
||||
);
|
||||
myImage = File(pickedImage.path);
|
||||
isloading = true;
|
||||
update();
|
||||
var response = await uploadImage(
|
||||
myImage!,
|
||||
{
|
||||
'driverID': box.read(BoxName.driverID).toString(),
|
||||
},
|
||||
link,
|
||||
);
|
||||
isloading = false;
|
||||
update();
|
||||
if (response['status'] == 'success') {
|
||||
Get.snackbar('Image Uploaded'.tr, 'Sucsses',
|
||||
backgroundColor: AppColor.greenColor);
|
||||
// Save the cropped image
|
||||
File savedCroppedImage = File(croppedFile!.path);
|
||||
print('link =$link');
|
||||
try {
|
||||
await uploadImage(
|
||||
savedCroppedImage,
|
||||
{
|
||||
'driverID':
|
||||
box.read(BoxName.driverID) ?? box.read(BoxName.passengerID),
|
||||
'imageType': imageType
|
||||
},
|
||||
link,
|
||||
);
|
||||
} catch (e) {
|
||||
Get.snackbar('Image Upload Failed'.tr, e.toString(),
|
||||
backgroundColor: AppColor.redColor);
|
||||
print(e);
|
||||
} finally {
|
||||
isloading = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +102,9 @@ class ImageController extends GetxController {
|
||||
var res = await http.Response.fromStream(myrequest);
|
||||
if (res.statusCode == 200) {
|
||||
return jsonDecode(res.body);
|
||||
} else {
|
||||
throw Exception(
|
||||
'Failed to upload image: ${res.statusCode} - ${res.body}');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,8 +107,10 @@ class MapPassengerController extends GetxController {
|
||||
bool isDriverInPassengerWay = false;
|
||||
bool isDriverArrivePassenger = false;
|
||||
bool startLocationFromMap = false;
|
||||
bool passengerStartLocationFromMap = false;
|
||||
bool workLocationFromMap = false;
|
||||
bool homeLocationFromMap = false;
|
||||
bool isPassengerRideLocationWidget = false;
|
||||
bool startLocationFromMap0 = false;
|
||||
bool startLocationFromMap1 = false;
|
||||
bool startLocationFromMap2 = false;
|
||||
@@ -213,6 +215,7 @@ class MapPassengerController extends GetxController {
|
||||
late double totalCostPassenger = 0;
|
||||
late double totalPassengerComfort = 0;
|
||||
late double totalPassengerComfortDiscount = 0;
|
||||
late double totalPassengerSpeedDiscount = 0;
|
||||
late double totalPassengerMotoDelivery = 0;
|
||||
late double totalDriver = 0;
|
||||
late double averageDuration = 0;
|
||||
@@ -1403,10 +1406,11 @@ class MapPassengerController extends GetxController {
|
||||
Future cancelRide() async {
|
||||
//print("rideConfirm=$rideConfirm");
|
||||
|
||||
if (rideConfirm == false) {
|
||||
if (rideConfirm == false && statusRide != 'Apply') {
|
||||
clearPlacesDestination();
|
||||
clearPolyline();
|
||||
// clearPolylineAll();
|
||||
print('rideConfirm before is $rideConfirm');
|
||||
data = [];
|
||||
changeCancelRidePageShow();
|
||||
if (rideId != 'yet') {
|
||||
@@ -1434,6 +1438,7 @@ class MapPassengerController extends GetxController {
|
||||
} else {
|
||||
clearPlacesDestination();
|
||||
clearPolyline();
|
||||
print('rideConfirm is $rideConfirm');
|
||||
data = [];
|
||||
await CRUD().post(link: AppLink.updateDriverOrder, payload: {
|
||||
"order_id": rideId.toString(), // Convert to String
|
||||
@@ -1484,7 +1489,7 @@ class MapPassengerController extends GetxController {
|
||||
} else {
|
||||
isMainBottomMenuMap = !isMainBottomMenuMap;
|
||||
mainBottomMenuMapHeight =
|
||||
isMainBottomMenuMap == true ? Get.height * .2 : Get.height * .45;
|
||||
isMainBottomMenuMap == true ? Get.height * .2 : Get.height * .55;
|
||||
isWayPointSheet = false;
|
||||
if (heightMenuBool == true) {
|
||||
getDrawerMenu();
|
||||
@@ -2361,17 +2366,22 @@ class MapPassengerController extends GetxController {
|
||||
var totalDriver1 = costDistance + costDuration;
|
||||
totalCostPassenger = totalDriver1 + (totalDriver1 * kazan / 100);
|
||||
totalPassenger = costSpeed + (costSpeed * kazan / 100);
|
||||
totalPassengerComfort = costComfort + (costComfort * kazan / 100);
|
||||
totalPassengerSpeed = costSpeed + (costSpeed * kazan / 100);
|
||||
totalPassengerComfort =
|
||||
(costComfort + (costComfort * kazan / 100)).ceilToDouble();
|
||||
totalPassengerSpeed =
|
||||
(costSpeed + (costSpeed * kazan / 100)).ceilToDouble();
|
||||
totalPassengerComfortDiscount =
|
||||
totalPassengerComfort + totalPassengerComfort * (kazan - 10) / 100;
|
||||
totalPassengerMotoDelivery = costDelivery + (costDelivery * kazan / 100);
|
||||
totalPassengerComfort + totalPassengerComfort * (kazan - 0) / 100;
|
||||
totalPassengerSpeedDiscount =
|
||||
totalPassengerSpeed + totalPassengerSpeed * (kazan - 2) / 100;
|
||||
totalPassengerMotoDelivery =
|
||||
(costDelivery + (costDelivery * kazan / 100)).ceilToDouble();
|
||||
totalDriver = totalDriver1 + (totalDriver1 * kazan / 100);
|
||||
tax = totalCostPassenger * kazan / 100;
|
||||
totalME = totalCostPassenger - tax;
|
||||
costForDriver = fuelPrice * (20 / 210) * distance;
|
||||
print('cost for driver = $costForDriver');
|
||||
if (totalCostPassenger < 20) {
|
||||
if (totalPassengerSpeed < 20) {
|
||||
// for eygpt 20 le open ride
|
||||
totalCostPassenger = 20;
|
||||
totalPassengerSpeed = 20;
|
||||
@@ -2491,7 +2501,7 @@ class MapPassengerController extends GetxController {
|
||||
payload: {'country': box.read(BoxName.countryCode).toString()},
|
||||
);
|
||||
if (res != 'failure') {
|
||||
// print(jsonDecode(res));
|
||||
print(jsonDecode(res));
|
||||
var json = jsonDecode(res);
|
||||
kazan = double.parse(json['message'][0]['kazan']);
|
||||
naturePrice = double.parse(json['message'][0]['naturePrice']);
|
||||
@@ -2511,7 +2521,7 @@ class MapPassengerController extends GetxController {
|
||||
payload: {'passenger_id': box.read(BoxName.passengerID)});
|
||||
if (res != 'failure') {
|
||||
print(jsonDecode(res)['message']['rating']);
|
||||
passengerRate = jsonDecode(res)['message']['rating'];
|
||||
passengerRate = jsonDecode(res)['message']['rating'] ?? 5;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -567,11 +567,19 @@ class MyTranslation extends Translations {
|
||||
"We Are Sorry That we dont have cars in your Location!":
|
||||
"نعتذر لعدم وجود سيارات في موقعك!",
|
||||
"Choose from Map": "اختر من الخريطة",
|
||||
'Pick your ride location on the map - Tap to confirm':
|
||||
'حدد موقع الالتقاء على الخريطة - اضغط للتأكيد',
|
||||
"To Work": "إلى العمل",
|
||||
'Closest & Cheapest': ' الأقرب ',
|
||||
"Work Saved": "تم حفظ العمل",
|
||||
"To Home": "إلى المنزل",
|
||||
"Home Saved": "تم حفظ المنزل",
|
||||
"Click here point": "انقر هنا نقطة",
|
||||
"Destination Selected":
|
||||
"تم تحديد الوجهة:", // "Tam تحديد al-waṣʿah:", (literally "The destination has been determined:")
|
||||
"Now select start pick":
|
||||
"حدد موقع الانطلاق الآن:", // "Ḥaddid mowāqiʿ al-inṭilāq al-ʾān:", (literally "Specify the starting location now:")
|
||||
"Pick from map": "اختيار من الخريطة",
|
||||
"Click here point": "حدد هذا المكان",
|
||||
"No Car in your site. Sorry!": "لا توجد سيارة في موقعك. آسف!",
|
||||
"Nearest Car for you about ": "أقرب سيارة لك حوالي ",
|
||||
"N/A": "غير متوفر",
|
||||
|
||||
Reference in New Issue
Block a user