titipata commited on
Commit
bfb28a3
·
verified ·
1 Parent(s): d62ed3f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -0
app.py CHANGED
@@ -53,6 +53,10 @@ def predict(img):
53
  as a dictionary:
54
  {label: confidence, label: confidence, ...}
55
  """
 
 
 
 
56
  img_data = img['composite']
57
  img_gray = Image.fromarray(img_data).convert('L').resize((28, 28))
58
  img_tensor = transforms.ToTensor()(img_gray).unsqueeze(0)
@@ -85,6 +89,8 @@ with gr.Blocks(js=js_func) as demo:
85
  image_mode="L",
86
  layers=False,
87
  eraser=None,
 
 
88
  ),
89
  outputs=gr.Label(label="Guess"),
90
  title="Thai Digit Handwritten Classification",
 
53
  as a dictionary:
54
  {label: confidence, label: confidence, ...}
55
  """
56
+ if img.get("composite") is not None:
57
+ if img["composite"].sum() == 0:
58
+ return {"No input sketch": 0.0}
59
+
60
  img_data = img['composite']
61
  img_gray = Image.fromarray(img_data).convert('L').resize((28, 28))
62
  img_tensor = transforms.ToTensor()(img_gray).unsqueeze(0)
 
89
  image_mode="L",
90
  layers=False,
91
  eraser=None,
92
+ width=400,
93
+ height=400
94
  ),
95
  outputs=gr.Label(label="Guess"),
96
  title="Thai Digit Handwritten Classification",