Spaces:
Sleeping
Sleeping
Update app/routes.py
Browse files- app/routes.py +9 -10
app/routes.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
from flask import Blueprint, jsonify, request, current_app
|
2 |
import io
|
3 |
import pandas as pd
|
@@ -56,7 +57,7 @@ def process_image():
|
|
56 |
if 'allergens' not in request.form:
|
57 |
logger.warning("Allergens not specified")
|
58 |
return jsonify({"error": "Allergens not specified"}), 400
|
59 |
-
|
60 |
file = request.files['file']
|
61 |
if file.filename == '':
|
62 |
logger.warning("No file selected")
|
@@ -72,22 +73,20 @@ def process_image():
|
|
72 |
user_allergens = [a.strip().lower() for a in request.form['allergens'].split(',')]
|
73 |
logger.info(f"Processing image for allergens: {user_allergens}")
|
74 |
|
75 |
-
file_bytes = file.read()
|
76 |
-
file_stream = io.BytesIO(file_bytes)
|
77 |
-
image = Image.open(file_stream)
|
78 |
-
|
79 |
-
extracted_text = ocr_model.process_image(image)
|
80 |
-
logger.info(f"Extracted text: {extracted_text}")
|
81 |
-
|
82 |
# تأكد من تهيئة محلل الحساسيات
|
83 |
if allergy_analyzer is None:
|
84 |
init_allergy_analyzer(current_app._get_current_object())
|
85 |
|
86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
response = {
|
89 |
"success": True,
|
90 |
-
"extracted_text": extracted_text,
|
91 |
"analysis": analysis_results,
|
92 |
"warnings": {
|
93 |
"has_allergens": len(analysis_results['detected_allergens']) > 0,
|
|
|
1 |
+
# routes.py
|
2 |
from flask import Blueprint, jsonify, request, current_app
|
3 |
import io
|
4 |
import pandas as pd
|
|
|
57 |
if 'allergens' not in request.form:
|
58 |
logger.warning("Allergens not specified")
|
59 |
return jsonify({"error": "Allergens not specified"}), 400
|
60 |
+
|
61 |
file = request.files['file']
|
62 |
if file.filename == '':
|
63 |
logger.warning("No file selected")
|
|
|
73 |
user_allergens = [a.strip().lower() for a in request.form['allergens'].split(',')]
|
74 |
logger.info(f"Processing image for allergens: {user_allergens}")
|
75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
# تأكد من تهيئة محلل الحساسيات
|
77 |
if allergy_analyzer is None:
|
78 |
init_allergy_analyzer(current_app._get_current_object())
|
79 |
|
80 |
+
# معالجة الصورة مباشرة دون حفظ النص المستخرج
|
81 |
+
file_bytes = file.read()
|
82 |
+
file_stream = io.BytesIO(file_bytes)
|
83 |
+
image = Image.open(file_stream)
|
84 |
+
|
85 |
+
# تحليل الصورة مباشرة
|
86 |
+
analysis_results = allergy_analyzer.analyze_image(image, user_allergens)
|
87 |
|
88 |
response = {
|
89 |
"success": True,
|
|
|
90 |
"analysis": analysis_results,
|
91 |
"warnings": {
|
92 |
"has_allergens": len(analysis_results['detected_allergens']) > 0,
|