sayi_ciz / app.py
zaferturan's picture
Upload 3 files
5523ece 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
with st.spinner("Model Yükleniyor. Lütfen bekleyiniz!.."):
model = load_model("model.keras")
st.title("Digit Recognition :writing_hand:")
st.write("El yazısı rakam tahmin aracı")
st.write("Aşağıdaki alana bir rakam çizin. Model kaç olduğunu tahmin etsin.")
rakamlar=[":zero:", ":one:", ":two:", ":three:", ":four:", ":five:", ":six:", ":seven:", ":eight:", ":nine:"]
col1, col2 = st.columns([1,2])
with col1:
canvas_result = st_canvas(
fill_color="rgb(0, 0, 0)", # Başlangıç dolgu rengi siyah
stroke_width=20,
stroke_color="rgb(255, 255, 255)", # Başlangıç çizgi rengi beyaz
background_color="rgb(0, 0, 0)", # Arka plan rengi siyah
update_streamlit=True, # update_streamlit parametresini False olarak ayarlayın
width=200,
height=200,
drawing_mode="freedraw",
key="canvas",
)
with col2:
if st.button("Tahmin Et"):
col21, col22 = st.columns(2)
with col21:
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.title("Sonuç")
st.title(rakamlar[predicted_class])
with col22:
st.write("Diğer değerler:")
for i in range(10):
if np.round(prediction[0][i], 3)>0.0:
st.write(i, ":",np.round(prediction[0][i] * 100, 2), "%")