Update app.py
Browse files
app.py
CHANGED
|
@@ -110,17 +110,25 @@ def predict():
|
|
| 110 |
print("Bytes length:", len(image_bytes))
|
| 111 |
print("First 50 bytes:", image_bytes[:50])
|
| 112 |
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
img = img.convert("RGB")
|
| 116 |
|
| 117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
-
|
| 120 |
-
logits = model(tensor)
|
| 121 |
-
probs = F.softmax(logits, dim=1).squeeze(0)
|
| 122 |
|
| 123 |
-
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
except Exception as e:
|
| 126 |
print("ERROR:", e)
|
|
|
|
| 110 |
print("Bytes length:", len(image_bytes))
|
| 111 |
print("First 50 bytes:", image_bytes[:50])
|
| 112 |
|
| 113 |
+
try:
|
| 114 |
+
data = file.read()
|
|
|
|
| 115 |
|
| 116 |
+
print("Filename:", file.filename)
|
| 117 |
+
print("Content-Type:", file.content_type)
|
| 118 |
+
print("Bytes length:", len(data))
|
| 119 |
+
|
| 120 |
+
img = Image.open(io.BytesIO(data))
|
| 121 |
+
print("Format:", img.format)
|
| 122 |
+
print("Size:", img.size)
|
| 123 |
+
|
| 124 |
+
img = img.convert("RGB")
|
| 125 |
|
| 126 |
+
tensor = transform(img).unsqueeze(0).to(device)
|
|
|
|
|
|
|
| 127 |
|
| 128 |
+
t0 = time.time()
|
| 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)
|