ibrahim yıldız
Upload 2 files
9247e34 verified
import streamlit as st
from streamlit_drawable_canvas import st_canvas
import numpy as np
from PIL import Image
import tensorflow as tf
from tensorflow.keras.models import load_model
# pip install streamlit-drawable-canvas
model = load_model("digit_model.h5")
st.title("Digit Recognition :writing_hand:")
st.write("Write a number between 0-9 on the board and let's see if the model can identify it!")
st.write('(it lives some hard time predicting 1. try to fill the whole space equaly.)')
numbers=[":zero:", ":one:", ":two:", ":three:", ":four:", ":five:", ":six:", ":seven:", ":eight:", ":nine:"]
canvas_result = st_canvas(
stroke_width=20,
stroke_color="rgb(255, 255, 255)",
background_color="rgb(33, 62, 40)",
update_streamlit=True,
width=200,
height=200,
drawing_mode="freedraw",
key="canvas",
)
if st.button("Predict"):
image_data = np.array(canvas_result.image_data)
image_data = image_data.astype(np.uint8)
image = Image.fromarray(image_data)
image = image.resize((28, 28)).convert("L")
image = np.array(image).reshape((1, 28, 28, 1)) / 255.0
prediction = model.predict(image)
predicted_class = np.argmax(prediction)
st.write(f"Your number is {numbers[predicted_class]} If this was wrong, your handwriting sucks!")
st.image("https://i.ytimg.com/vi/NlUVkNJ3Rcw/maxresdefault.jpg")