5/15/1
This commit is contained in:
@@ -106,77 +106,32 @@ class CRUD {
|
||||
Future.delayed(const Duration(seconds: 2));
|
||||
var extractedString =
|
||||
await arabicTextExtractByVisionAndAI(imagePath: imagePath);
|
||||
// print('extractedString');
|
||||
var json = jsonDecode(extractedString);
|
||||
// print(extractedString);
|
||||
// print(json);
|
||||
var textValues = getAllTextValuesWithLineNumbers(json);
|
||||
// List<String> textValues = getAllTextValues(json);
|
||||
|
||||
print('extractedData');
|
||||
var json = jsonDecode(extractedString);
|
||||
var textValues = extractTextFromLines(json);
|
||||
print(textValues);
|
||||
await AI().geminiAiExtraction(prompt, textValues);
|
||||
// await Get.put(AI()).geminiAiExtraction(prompt, textValues);
|
||||
await Get.put(AI()).anthropicAI(textValues, prompt, imagePath);
|
||||
}
|
||||
|
||||
Map<String, List<Map<String, String>>> getAllTextValuesWithLineNumbers(
|
||||
Map json) {
|
||||
Map<String, List<Map<String, String>>> output = {};
|
||||
int lineNumber = 1;
|
||||
String extractTextFromLines(Map<String, dynamic> jsonData) {
|
||||
final readResult = jsonData['readResult'];
|
||||
final blocks = readResult['blocks'];
|
||||
|
||||
if (json.containsKey('regions')) {
|
||||
List<dynamic> regions = json['regions'];
|
||||
for (Map<String, dynamic> region in regions) {
|
||||
if (region.containsKey('lines')) {
|
||||
List<dynamic> lines = region['lines'];
|
||||
List<Map<String, String>> linesWithText = [];
|
||||
for (Map<String, dynamic> line in lines) {
|
||||
if (line.containsKey('words')) {
|
||||
List<dynamic> words = line['words'];
|
||||
String lineText = "";
|
||||
for (Map<String, dynamic> word in words) {
|
||||
if (word.containsKey('text')) {
|
||||
lineText += word['text'] + " ";
|
||||
}
|
||||
}
|
||||
lineText = lineText.trim();
|
||||
linesWithText.add(
|
||||
{"line_number": lineNumber.toString(), "text": lineText});
|
||||
lineNumber++;
|
||||
}
|
||||
}
|
||||
output["region_${region.hashCode}"] = linesWithText;
|
||||
}
|
||||
final StringBuffer buffer = StringBuffer();
|
||||
|
||||
for (final block in blocks) {
|
||||
final lines = block['lines'];
|
||||
for (final line in lines) {
|
||||
final text = line['text'];
|
||||
buffer.write(text);
|
||||
buffer.write('\n');
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
return buffer.toString().trim();
|
||||
}
|
||||
|
||||
// List<String> getAllTextValues(Map json) {
|
||||
// List<String> textValues = [];
|
||||
|
||||
// if (json.containsKey('regions')) {
|
||||
// List<dynamic> regions = json['regions'];
|
||||
// for (Map<String, dynamic> region in regions) {
|
||||
// if (region.containsKey('lines')) {
|
||||
// List<dynamic> lines = region['lines'];
|
||||
// for (Map<String, dynamic> line in lines) {
|
||||
// if (line.containsKey('words')) {
|
||||
// List<dynamic> words = line['words'];
|
||||
// for (Map<String, dynamic> word in words) {
|
||||
// if (word.containsKey('text')) {
|
||||
// textValues.add(word['text']);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// return textValues;
|
||||
// }
|
||||
|
||||
Future<dynamic> arabicTextExtractByVisionAndAI({
|
||||
required String imagePath,
|
||||
}) async {
|
||||
@@ -184,16 +139,14 @@ class CRUD {
|
||||
'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)}.jpg';
|
||||
|
||||
var request = http.Request(
|
||||
'POST',
|
||||
Uri.parse(
|
||||
'https://ocrhamza.cognitiveservices.azure.com/vision/v2.1/ocr?language=ar'));
|
||||
var request = http.Request('POST', Uri.parse(
|
||||
// 'https://ocrhamza.cognitiveservices.azure.com/vision/v2.1/ocr?language=ar'));
|
||||
// 'https://eastus.api.cognitive.microsoft.com/vision/v3.2/ocr'
|
||||
'https://eastus.api.cognitive.microsoft.com/computervision/imageanalysis:analyze?features=caption,read&model-version=latest&language=en&api-version=2024-02-01'));
|
||||
request.body = json.encode({"url": imagePathFull});
|
||||
request.headers.addAll(headers);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user