Spaces:
Runtime error
Runtime error
ibrahim yıldız
commited on
Upload 2 files
Browse files- app.py +40 -0
- digit_model.h5 +3 -0
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from streamlit_drawable_canvas import st_canvas
|
| 3 |
+
import numpy as np
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import tensorflow as tf
|
| 6 |
+
from tensorflow.keras.models import load_model
|
| 7 |
+
|
| 8 |
+
# pip install streamlit-drawable-canvas
|
| 9 |
+
|
| 10 |
+
model = load_model("digit_model.h5")
|
| 11 |
+
|
| 12 |
+
st.title("Digit Recognition :writing_hand:")
|
| 13 |
+
st.write("Write a number between 0-9 on the board and let's see if the model can identify it!")
|
| 14 |
+
st.write('(it lives some hard time predicting 1. try to fill the whole space equaly.)')
|
| 15 |
+
|
| 16 |
+
numbers=[":zero:", ":one:", ":two:", ":three:", ":four:", ":five:", ":six:", ":seven:", ":eight:", ":nine:"]
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
canvas_result = st_canvas(
|
| 20 |
+
stroke_width=20,
|
| 21 |
+
stroke_color="rgb(255, 255, 255)",
|
| 22 |
+
background_color="rgb(33, 62, 40)",
|
| 23 |
+
update_streamlit=True,
|
| 24 |
+
width=200,
|
| 25 |
+
height=200,
|
| 26 |
+
drawing_mode="freedraw",
|
| 27 |
+
key="canvas",
|
| 28 |
+
)
|
| 29 |
+
if st.button("Predict"):
|
| 30 |
+
image_data = np.array(canvas_result.image_data)
|
| 31 |
+
image_data = image_data.astype(np.uint8)
|
| 32 |
+
image = Image.fromarray(image_data)
|
| 33 |
+
image = image.resize((28, 28)).convert("L")
|
| 34 |
+
image = np.array(image).reshape((1, 28, 28, 1)) / 255.0
|
| 35 |
+
|
| 36 |
+
prediction = model.predict(image)
|
| 37 |
+
predicted_class = np.argmax(prediction)
|
| 38 |
+
st.write(f"Your number is {numbers[predicted_class]} If this was wrong, your handwriting sucks!")
|
| 39 |
+
|
| 40 |
+
st.image("https://i.ytimg.com/vi/NlUVkNJ3Rcw/maxresdefault.jpg")
|
digit_model.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:442fec1bc3a965146a4ce13413f210a8f433014f7c324fffee4b6557b2f63eda
|
| 3 |
+
size 7150272
|