Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -110,13 +110,27 @@ CORS(app)
|
|
| 110 |
@app.route("/analyze", methods=["POST"])
|
| 111 |
def analyze():
|
| 112 |
result = {"text_result": [], "image_result": []}
|
|
|
|
| 113 |
if "content" in request.form:
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
| 115 |
if "image" in request.files:
|
| 116 |
-
|
|
|
|
|
|
|
| 117 |
image = Image.open(image_file.stream).convert("RGB")
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
return jsonify(result)
|
| 120 |
|
| 121 |
if __name__ == "__main__":
|
| 122 |
-
app.run(host="0.0.0.0", port=
|
|
|
|
| 110 |
@app.route("/analyze", methods=["POST"])
|
| 111 |
def analyze():
|
| 112 |
result = {"text_result": [], "image_result": []}
|
| 113 |
+
# 🧠 PHÂN TÍCH TEXT
|
| 114 |
if "content" in request.form:
|
| 115 |
+
text_input = request.form["content"]
|
| 116 |
+
result["text_result"] = predict_text(text_input)
|
| 117 |
+
|
| 118 |
+
# 🧠 PHÂN TÍCH NHIỀU ẢNH
|
| 119 |
if "image" in request.files:
|
| 120 |
+
# request.files có thể chứa nhiều file trùng key "image"
|
| 121 |
+
image_files = request.files.getlist("image")
|
| 122 |
+
for image_file in image_files:
|
| 123 |
image = Image.open(image_file.stream).convert("RGB")
|
| 124 |
+
image_result = predict_image(image)
|
| 125 |
+
# nếu model trả về 1 dict → thêm vào list
|
| 126 |
+
if isinstance(image_result, dict):
|
| 127 |
+
result["image_result"].append(image_result)
|
| 128 |
+
# nếu model trả về list → nối list
|
| 129 |
+
elif isinstance(image_result, list):
|
| 130 |
+
result["image_result"].extend(image_result)
|
| 131 |
+
|
| 132 |
+
# Nếu không có ảnh nào → để rỗng []
|
| 133 |
return jsonify(result)
|
| 134 |
|
| 135 |
if __name__ == "__main__":
|
| 136 |
+
app.run(host="0.0.0.0", port=5001, debug=True)
|