Update app.py
Browse files
app.py
CHANGED
|
@@ -100,30 +100,29 @@ def predict():
|
|
| 100 |
return jsonify({"error": "No file uploaded"}), 400
|
| 101 |
|
| 102 |
file = request.files["file"]
|
| 103 |
-
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
try:
|
| 107 |
-
img = Image.open(io.BytesIO(
|
|
|
|
|
|
|
| 108 |
tensor = transform(img).unsqueeze(0).to(device)
|
| 109 |
|
| 110 |
-
t0 = time.time()
|
| 111 |
with torch.no_grad():
|
| 112 |
logits = model(tensor)
|
| 113 |
-
probs
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
[{"class": CLASSES[i], "probability": float(probs[i])} for i in range(10)],
|
| 118 |
-
key=lambda x: x["probability"], reverse=True
|
| 119 |
-
)
|
| 120 |
-
return jsonify({
|
| 121 |
-
"top_class": results[0]["class"],
|
| 122 |
-
"top_probability": results[0]["probability"],
|
| 123 |
-
"all_predictions": results,
|
| 124 |
-
"inference_ms": ms
|
| 125 |
-
})
|
| 126 |
except Exception as e:
|
|
|
|
| 127 |
return jsonify({"error": str(e)}), 500
|
| 128 |
|
| 129 |
@app.route("/model-info")
|
|
|
|
| 100 |
return jsonify({"error": "No file uploaded"}), 400
|
| 101 |
|
| 102 |
file = request.files["file"]
|
| 103 |
+
|
| 104 |
+
print("Filename:", file.filename)
|
| 105 |
+
print("Content-Type:", file.content_type)
|
| 106 |
+
|
| 107 |
+
image_bytes = file.read()
|
| 108 |
+
|
| 109 |
+
print("Bytes length:", len(image_bytes))
|
| 110 |
+
print("First 50 bytes:", image_bytes[:50])
|
| 111 |
|
| 112 |
try:
|
| 113 |
+
img = Image.open(io.BytesIO(image_bytes))
|
| 114 |
+
img = img.convert("RGB")
|
| 115 |
+
|
| 116 |
tensor = transform(img).unsqueeze(0).to(device)
|
| 117 |
|
|
|
|
| 118 |
with torch.no_grad():
|
| 119 |
logits = model(tensor)
|
| 120 |
+
probs = F.softmax(logits, dim=1).squeeze(0)
|
| 121 |
+
|
| 122 |
+
return jsonify({"success": True})
|
| 123 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
except Exception as e:
|
| 125 |
+
print("ERROR:", e)
|
| 126 |
return jsonify({"error": str(e)}), 500
|
| 127 |
|
| 128 |
@app.route("/model-info")
|