File size: 1,859 Bytes
5523ece
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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), "%")