Update app.py
Browse files
app.py
CHANGED
|
@@ -97,41 +97,34 @@ def index():
|
|
| 97 |
|
| 98 |
@app.route("/predict", methods=["POST"])
|
| 99 |
def predict():
|
|
|
|
| 100 |
if "file" not in request.files:
|
| 101 |
return jsonify({"error": "No file uploaded"}), 400
|
| 102 |
|
| 103 |
file = request.files["file"]
|
| 104 |
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
image_bytes = file.read()
|
| 109 |
-
|
| 110 |
-
print("Bytes length:", len(image_bytes))
|
| 111 |
-
print("First 50 bytes:", image_bytes[:50])
|
| 112 |
|
| 113 |
-
|
| 114 |
-
|
|
|
|
| 115 |
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
|
| 120 |
-
|
| 121 |
-
print("Format:", img.format)
|
| 122 |
-
print("Size:", img.size)
|
| 123 |
|
| 124 |
-
|
| 125 |
|
| 126 |
-
|
|
|
|
| 127 |
|
| 128 |
-
|
| 129 |
-
with torch.no_grad():
|
| 130 |
-
logits = model(tensor)
|
| 131 |
-
probs = F.softmax(logits, dim=1).squeeze(0)
|
| 132 |
|
| 133 |
except Exception as e:
|
| 134 |
-
print("ERROR:", e)
|
| 135 |
return jsonify({"error": str(e)}), 500
|
| 136 |
|
| 137 |
@app.route("/model-info")
|
|
|
|
| 97 |
|
| 98 |
@app.route("/predict", methods=["POST"])
|
| 99 |
def predict():
|
| 100 |
+
|
| 101 |
if "file" not in request.files:
|
| 102 |
return jsonify({"error": "No file uploaded"}), 400
|
| 103 |
|
| 104 |
file = request.files["file"]
|
| 105 |
|
| 106 |
+
try:
|
| 107 |
+
data = file.read()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
+
print("Filename:", file.filename)
|
| 110 |
+
print("Content-Type:", file.content_type)
|
| 111 |
+
print("Bytes length:", len(data))
|
| 112 |
|
| 113 |
+
img = Image.open(io.BytesIO(data))
|
| 114 |
+
print("Format:", img.format)
|
| 115 |
+
print("Size:", img.size)
|
| 116 |
|
| 117 |
+
img = img.convert("RGB")
|
|
|
|
|
|
|
| 118 |
|
| 119 |
+
tensor = transform(img).unsqueeze(0).to(device)
|
| 120 |
|
| 121 |
+
with torch.no_grad():
|
| 122 |
+
logits = model(tensor)
|
| 123 |
|
| 124 |
+
return jsonify({"success": True})
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
except Exception as e:
|
| 127 |
+
print("ERROR:", repr(e))
|
| 128 |
return jsonify({"error": str(e)}), 500
|
| 129 |
|
| 130 |
@app.route("/model-info")
|