Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
|
| 3 |
|
| 4 |
-
import numpy as np
|
| 5 |
-
import gradio as gr
|
| 6 |
from tensorflow.keras.models import load_model
|
| 7 |
model = load_model('saved_model.keras')
|
| 8 |
|
|
@@ -12,7 +12,6 @@ def predict_number(image):
|
|
| 12 |
image_grayScale= np.mean(image_rgb, axis=-1).astype(np.uint8)
|
| 13 |
|
| 14 |
image_grayScale = image_grayScale.reshape(1, 280, 280, 1)
|
| 15 |
-
print(image_grayScale)
|
| 16 |
preds = model.predict(image_grayScale)[0]
|
| 17 |
|
| 18 |
return {str(i): float(preds[i]) for i in range(10)}
|
|
@@ -29,29 +28,33 @@ with gr.Blocks() as demo:
|
|
| 29 |
3. **Click 'Clear canvas'** to clear the canvas.
|
| 30 |
|
| 31 |
""")
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
btn = gr.Button("Recognize", variant="primary")
|
| 46 |
clear_btn = gr.Button("Clear canvas", variant="stop")
|
| 47 |
-
|
| 48 |
|
| 49 |
clear_btn.click(lambda: {"background": np.zeros((280, 280, 3), dtype=np.uint8), "layers": [], "composite": None},
|
| 50 |
outputs=sketch_pad)
|
| 51 |
btn.click(predict_number, inputs=sketch_pad, outputs=output)
|
|
|
|
| 52 |
gr.Markdown("""
|
| 53 |
## GitHub Repository
|
| 54 |
-
If you want to see the training process, data augmentation, and how the model was built,
|
| 55 |
-
check out the **[main_analysis.ipynb](https://github.com/Arcus72/Image-Digit-Classification)** file in my GitHub repository.""")
|
| 56 |
|
| 57 |
demo.launch(theme=gr.themes.Soft())
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import gradio as gr
|
| 3 |
import os
|
| 4 |
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
|
| 5 |
|
|
|
|
|
|
|
| 6 |
from tensorflow.keras.models import load_model
|
| 7 |
model = load_model('saved_model.keras')
|
| 8 |
|
|
|
|
| 12 |
image_grayScale= np.mean(image_rgb, axis=-1).astype(np.uint8)
|
| 13 |
|
| 14 |
image_grayScale = image_grayScale.reshape(1, 280, 280, 1)
|
|
|
|
| 15 |
preds = model.predict(image_grayScale)[0]
|
| 16 |
|
| 17 |
return {str(i): float(preds[i]) for i in range(10)}
|
|
|
|
| 28 |
3. **Click 'Clear canvas'** to clear the canvas.
|
| 29 |
|
| 30 |
""")
|
| 31 |
+
with gr.Row():
|
| 32 |
+
with gr.Column():
|
| 33 |
+
sketch_pad = gr.Sketchpad(
|
| 34 |
+
label="Draw here (White on Black)",
|
| 35 |
+
layers=False,
|
| 36 |
+
canvas_size=(280, 280),
|
| 37 |
+
brush=gr.Brush(colors=["#FFFFFF"], default_color="#FFFFFF", default_size=10),
|
| 38 |
+
value={
|
| 39 |
+
"background": np.zeros((280, 280, 3), dtype=np.uint8),
|
| 40 |
+
"layers": [],
|
| 41 |
+
"composite": None
|
| 42 |
+
},
|
| 43 |
+
type="numpy"
|
| 44 |
+
)
|
| 45 |
+
with gr.Column():
|
| 46 |
+
output = gr.Label(num_top_classes=3, label="Prediction")
|
| 47 |
|
| 48 |
btn = gr.Button("Recognize", variant="primary")
|
| 49 |
clear_btn = gr.Button("Clear canvas", variant="stop")
|
| 50 |
+
|
| 51 |
|
| 52 |
clear_btn.click(lambda: {"background": np.zeros((280, 280, 3), dtype=np.uint8), "layers": [], "composite": None},
|
| 53 |
outputs=sketch_pad)
|
| 54 |
btn.click(predict_number, inputs=sketch_pad, outputs=output)
|
| 55 |
+
|
| 56 |
gr.Markdown("""
|
| 57 |
## GitHub Repository
|
| 58 |
+
If you want to see the training process, data augmentation, and how the model was built, check out the **[main_analysis.ipynb](https://github.com/Arcus72/Image-Digit-Classification)** file in my GitHub repository.""")
|
|
|
|
| 59 |
|
| 60 |
demo.launch(theme=gr.themes.Soft())
|