Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -43,6 +43,7 @@ else:
|
|
| 43 |
model.fit(x_train, y_train, epochs=5, batch_size=32, validation_data=(x_test, y_test), verbose=1)
|
| 44 |
|
| 45 |
# Save model
|
|
|
|
| 46 |
model.save(MODEL_PATH)
|
| 47 |
print(f"💾 Model saved to {MODEL_PATH}")
|
| 48 |
|
|
@@ -113,12 +114,15 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 113 |
image_mode="L", # Grayscale mode
|
| 114 |
canvas_size=(200, 200),
|
| 115 |
brush=gr.Brush(default_size=20),
|
| 116 |
-
#
|
| 117 |
-
#
|
| 118 |
-
sources=["
|
|
|
|
|
|
|
|
|
|
| 119 |
)
|
| 120 |
-
#
|
| 121 |
-
|
| 122 |
clear_btn = gr.Button("🧹 Clear Canvas")
|
| 123 |
|
| 124 |
with gr.Column():
|
|
@@ -139,13 +143,15 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 139 |
show_progress=False # Optional: Disable progress bar for smoother drawing
|
| 140 |
)
|
| 141 |
|
| 142 |
-
#
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
|
|
|
| 148 |
|
|
|
|
| 149 |
clear_btn.click(fn=lambda: None, inputs=None, outputs=sketchpad)
|
| 150 |
|
| 151 |
demo.launch(debug=True)
|
|
|
|
| 43 |
model.fit(x_train, y_train, epochs=5, batch_size=32, validation_data=(x_test, y_test), verbose=1)
|
| 44 |
|
| 45 |
# Save model
|
| 46 |
+
# Note: Consider using the native Keras format as suggested: model.save(MODEL_PATH.replace(".h5", ".keras"))
|
| 47 |
model.save(MODEL_PATH)
|
| 48 |
print(f"💾 Model saved to {MODEL_PATH}")
|
| 49 |
|
|
|
|
| 114 |
image_mode="L", # Grayscale mode
|
| 115 |
canvas_size=(200, 200),
|
| 116 |
brush=gr.Brush(default_size=20),
|
| 117 |
+
# Removed type="numpy" - handle conversion in the function
|
| 118 |
+
# Removed invalid source "canvas". Only use valid ones if specifying.
|
| 119 |
+
# sources=["upload"] # Example: only allow uploads
|
| 120 |
+
# sources=["upload", "clipboard"] # Example: allow uploads and clipboard
|
| 121 |
+
# If you want drawing AND uploads, just remove the 'sources' line entirely.
|
| 122 |
+
# The canvas is the default and always available unless explicitly disabled.
|
| 123 |
)
|
| 124 |
+
# A separate upload button can still be used if preferred
|
| 125 |
+
upload_btn = gr.UploadButton("📁 Upload Image", file_types=["image"])
|
| 126 |
clear_btn = gr.Button("🧹 Clear Canvas")
|
| 127 |
|
| 128 |
with gr.Column():
|
|
|
|
| 143 |
show_progress=False # Optional: Disable progress bar for smoother drawing
|
| 144 |
)
|
| 145 |
|
| 146 |
+
# Connect the upload button event
|
| 147 |
+
upload_btn.upload(
|
| 148 |
+
fn=predict_digit,
|
| 149 |
+
inputs=upload_btn,
|
| 150 |
+
outputs=[output_label, output_bars],
|
| 151 |
+
show_progress=False
|
| 152 |
+
)
|
| 153 |
|
| 154 |
+
# Connect the clear button
|
| 155 |
clear_btn.click(fn=lambda: None, inputs=None, outputs=sketchpad)
|
| 156 |
|
| 157 |
demo.launch(debug=True)
|