Download app.py from ytrsoymr/HandWrittenDigitRecognition: direct link, hf CLI and curl.
- Browser
- Download file 750 Bytes
-
https://huggingface.co/spaces/ytrsoymr/HandWrittenDigitRecognition/resolve/main/app.py
- Command line
-
hf download hf://spaces/ytrsoymr/HandWrittenDigitRecognition/app.py
-
curl -L -o app.py https://huggingface.co/spaces/ytrsoymr/HandWrittenDigitRecognition/resolve/main/app.py
750 Bytes
| 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') # Convert to grayscale | |
| 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)}`") | |