Spaces:
Sleeping
Sleeping
Update app/routes.py
Browse files- app/routes.py +12 -14
app/routes.py
CHANGED
@@ -54,10 +54,6 @@ def process_image():
|
|
54 |
logger.warning("No file uploaded")
|
55 |
return jsonify({"error": "No file uploaded"}), 400
|
56 |
|
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")
|
@@ -70,24 +66,26 @@ def process_image():
|
|
70 |
"supported_formats": list(ALLOWED_EXTENSIONS)
|
71 |
}), 400
|
72 |
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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(
|
87 |
-
image,
|
88 |
-
user_allergens,
|
89 |
-
current_app.config.get('CLAUDE_API_KEY')
|
90 |
-
)
|
91 |
|
92 |
response = {
|
93 |
"success": True,
|
@@ -99,7 +97,7 @@ def process_image():
|
|
99 |
}
|
100 |
}
|
101 |
|
102 |
-
logger.info(
|
103 |
return jsonify(response)
|
104 |
|
105 |
except Exception as e:
|
|
|
54 |
logger.warning("No file uploaded")
|
55 |
return jsonify({"error": "No file uploaded"}), 400
|
56 |
|
|
|
|
|
|
|
|
|
57 |
file = request.files['file']
|
58 |
if file.filename == '':
|
59 |
logger.warning("No file selected")
|
|
|
66 |
"supported_formats": list(ALLOWED_EXTENSIONS)
|
67 |
}), 400
|
68 |
|
69 |
+
# القائمة الثابتة للحساسيات (بدلاً من إدخال المستخدم)
|
70 |
+
FIXED_ALLERGENS = [
|
71 |
+
"dairy", "eggs", "peanuts", "soy",
|
72 |
+
"tree nuts", "wheat", "fish",
|
73 |
+
"shellfish", "sesame"
|
74 |
+
]
|
75 |
+
|
76 |
+
logger.info(f"Processing image for fixed allergens: {FIXED_ALLERGENS}")
|
77 |
|
78 |
# تأكد من تهيئة محلل الحساسيات
|
79 |
if allergy_analyzer is None:
|
80 |
init_allergy_analyzer(current_app._get_current_object())
|
81 |
|
82 |
+
# معالجة الصورة
|
83 |
file_bytes = file.read()
|
84 |
file_stream = io.BytesIO(file_bytes)
|
85 |
image = Image.open(file_stream)
|
86 |
|
87 |
+
# تحليل الصورة باستخدام القائمة الثابتة
|
88 |
+
analysis_results = allergy_analyzer.analyze_image(image, FIXED_ALLERGENS)
|
|
|
|
|
|
|
|
|
89 |
|
90 |
response = {
|
91 |
"success": True,
|
|
|
97 |
}
|
98 |
}
|
99 |
|
100 |
+
logger.info("Analysis completed successfully")
|
101 |
return jsonify(response)
|
102 |
|
103 |
except Exception as e:
|