|
|
import streamlit as st |
|
|
import numpy as np |
|
|
import tensorflow as tf |
|
|
from PIL import Image, ImageOps |
|
|
|
|
|
model = tf.keras.models.load_model("model.keras", compile=False) |
|
|
|
|
|
st.title(" Handwritten Digit Detection") |
|
|
st.write("Upload an image of a digit (28x28 grayscale preferred).") |
|
|
|
|
|
uploaded_file = st.file_uploader("Choose an image...", type=["png", "jpg", "jpeg"]) |
|
|
|
|
|
if uploaded_file is not None: |
|
|
image = Image.open(uploaded_file).convert('L') |
|
|
image = ImageOps.invert(image) |
|
|
image = image.resize((28, 28)) |
|
|
img_array = np.array(image).reshape(1, 28, 28, 1) / 255.0 |
|
|
|
|
|
st.image(image, caption="Processed Input", width=150) |
|
|
pred = model.predict(img_array) |
|
|
st.write(f"### Predicted Digit: `{np.argmax(pred)}`") |
|
|
|