Scribbler310 commited on
Commit
10b2987
·
verified ·
1 Parent(s): e932bc5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -10,7 +10,7 @@ def classify_digit(image):
10
  if image is None:
11
  return None
12
 
13
- # Robust check: Gradio 4.x Sketchpad might return a dictionary
14
  if isinstance(image, dict):
15
  image = image['composite']
16
 
@@ -46,7 +46,6 @@ def classify_digit(image):
46
  return {str(i): float(prediction[i]) for i in range(10)}
47
 
48
  # --- UI SETUP ---
49
- # We use gr.Blocks to create a custom layout with Tabs
50
  with gr.Blocks() as demo:
51
  gr.Markdown("## Handwritten Digit Recognizer")
52
  gr.Markdown("Draw a digit (0-9) or upload a photo to test the model.")
@@ -54,12 +53,17 @@ with gr.Blocks() as demo:
54
  with gr.Tabs():
55
  # Tab 1: Drawing Interface
56
  with gr.Tab("Draw Digit"):
57
- sketchpad = gr.Sketchpad(label="Draw Here", type="numpy", brush=gr.Brush(color="#000000", thickness=20))
 
 
 
 
 
58
  btn_draw = gr.Button("Predict Drawing", variant="primary")
59
 
60
  # Tab 2: Upload Interface
61
  with gr.Tab("Upload Photo"):
62
- # sources=["upload", "clipboard"] fixes your specific error
63
  upload = gr.Image(label="Upload Image", sources=["upload", "clipboard"], type="numpy")
64
  btn_upload = gr.Button("Predict Upload", variant="primary")
65
 
 
10
  if image is None:
11
  return None
12
 
13
+ # Robust check: Gradio 4.x Sketchpad returns a dictionary {'background':..., 'layers':..., 'composite':...}
14
  if isinstance(image, dict):
15
  image = image['composite']
16
 
 
46
  return {str(i): float(prediction[i]) for i in range(10)}
47
 
48
  # --- UI SETUP ---
 
49
  with gr.Blocks() as demo:
50
  gr.Markdown("## Handwritten Digit Recognizer")
51
  gr.Markdown("Draw a digit (0-9) or upload a photo to test the model.")
 
53
  with gr.Tabs():
54
  # Tab 1: Drawing Interface
55
  with gr.Tab("Draw Digit"):
56
+ # FIX: Use 'default_size' and 'colors' instead of 'thickness' and 'color'
57
+ sketchpad = gr.Sketchpad(
58
+ label="Draw Here",
59
+ type="numpy",
60
+ brush=gr.Brush(colors=["#000000"], default_size=20)
61
+ )
62
  btn_draw = gr.Button("Predict Drawing", variant="primary")
63
 
64
  # Tab 2: Upload Interface
65
  with gr.Tab("Upload Photo"):
66
+ # FIX: Use 'sources=["upload", "clipboard"]' to avoid the source list error
67
  upload = gr.Image(label="Upload Image", sources=["upload", "clipboard"], type="numpy")
68
  btn_upload = gr.Button("Predict Upload", variant="primary")
69