Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -14,13 +14,25 @@ transform = transforms.Compose([
|
|
14 |
transforms.ToTensor(),
|
15 |
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
|
16 |
])
|
|
|
|
|
17 |
def predict(image):
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
gr.Interface(
|
26 |
fn=predict,
|
|
|
14 |
transforms.ToTensor(),
|
15 |
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
|
16 |
])
|
17 |
+
|
18 |
+
|
19 |
def predict(image):
|
20 |
+
try:
|
21 |
+
print("Received image:", image)
|
22 |
+
image = transform(image).unsqueeze(0)
|
23 |
+
print("Transformed image shape:", image.shape)
|
24 |
+
|
25 |
+
# Model inference
|
26 |
+
with torch.no_grad():
|
27 |
+
output = model(image)
|
28 |
+
print("Model output:", output)
|
29 |
+
class_idx = torch.argmax(output, dim=1).item()
|
30 |
+
|
31 |
+
return "Diagram" if class_idx == 1 else "Not Diagram"
|
32 |
+
|
33 |
+
except Exception as e:
|
34 |
+
print("Error during prediction:", str(e))
|
35 |
+
return f"Prediction Error: {str(e)}"
|
36 |
|
37 |
gr.Interface(
|
38 |
fn=predict,
|