titipata commited on
Commit
63ef10c
·
verified ·
1 Parent(s): 1289d42

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
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 [("Error", 1.0)]
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 [(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"])),
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 ด้านล่างเพื่อทำนายผลตัวเลข ตั้งแต่ ๐ (ศูนย์) ๑ (หนึ่ง) ๒ (สอง) ๓ (สาม) ๔ (สี่) ๕ (ห้า) ๖ (หก) ๗ (เจ็ด) ๘ (แปด) จนถึง ๙ (เก้า)",