Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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"]
|
| 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 |
|