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,15 +69,15 @@ 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 |
-
return
|
73 |
except Exception as e:
|
74 |
print(f"Error in prediction: {str(e)}")
|
75 |
-
return
|
76 |
|
77 |
|
78 |
demo = gr.Interface(
|
79 |
fn=predict,
|
80 |
-
inputs=gr.Sketchpad(label="Draw Here", brush=gr.Brush(default_size=20, default_color="#000000", colors=["#000000"])),
|
81 |
outputs=gr.Label(label="Guess"),
|
82 |
title="Thai Digit Handwritten Classification",
|
83 |
description="ทดลองวาดภาพตัวอักษรเลขไทยลงใน Sketchpad ด้านล่างเพื่อทำนายผลตัวเลข ตั้งแต่ ๐ (ศูนย์) ๑ (หนึ่ง) ๒ (สอง) ๓ (สาม) ๔ (สี่) ๕ (ห้า) ๖ (หก) ๗ (เจ็ด) ๘ (แปด) จนถึง ๙ (เก้า)",
|
|
|
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(
|
79 |
fn=predict,
|
80 |
+
inputs=gr.Sketchpad(label="Draw Here", brush=gr.Brush(default_size=20, default_color="#000000", colors=["#000000"]), image_mode="L"),
|
81 |
outputs=gr.Label(label="Guess"),
|
82 |
title="Thai Digit Handwritten Classification",
|
83 |
description="ทดลองวาดภาพตัวอักษรเลขไทยลงใน Sketchpad ด้านล่างเพื่อทำนายผลตัวเลข ตั้งแต่ ๐ (ศูนย์) ๑ (หนึ่ง) ๒ (สอง) ๓ (สาม) ๔ (สี่) ๕ (ห้า) ๖ (หก) ๗ (เจ็ด) ๘ (แปด) จนถึง ๙ (เก้า)",
|