Update app.py
Browse files
app.py
CHANGED
@@ -57,7 +57,7 @@ def predict(img):
|
|
57 |
|
58 |
try:
|
59 |
if img is None or not isinstance(img, dict) or 'image' not in img:
|
60 |
-
return
|
61 |
|
62 |
img_data = img['image']
|
63 |
img_gray = Image.fromarray(img_data).convert('L').resize((28, 28))
|
@@ -69,11 +69,10 @@ def predict(img):
|
|
69 |
|
70 |
probs, indices = torch.topk(probs, 5) # select top 5
|
71 |
probs, indices = probs.tolist(), indices.tolist() # transform to list
|
72 |
-
|
73 |
-
return confidences
|
74 |
except Exception as e:
|
75 |
print(f"Error in prediction: {str(e)}")
|
76 |
-
return
|
77 |
|
78 |
|
79 |
demo = gr.Interface(
|
|
|
57 |
|
58 |
try:
|
59 |
if img is None or not isinstance(img, dict) or 'image' not in img:
|
60 |
+
return [("Error", 1.0)]
|
61 |
|
62 |
img_data = img['image']
|
63 |
img_gray = Image.fromarray(img_data).convert('L').resize((28, 28))
|
|
|
69 |
|
70 |
probs, indices = torch.topk(probs, 5) # select top 5
|
71 |
probs, indices = probs.tolist(), indices.tolist() # transform to list
|
72 |
+
return [(LABELS[i], float(v)) for i, v in zip(indices, probs)]
|
|
|
73 |
except Exception as e:
|
74 |
print(f"Error in prediction: {str(e)}")
|
75 |
+
return [("Error", 1.0)]
|
76 |
|
77 |
|
78 |
demo = gr.Interface(
|