ytrsoymr commited on
Commit
6ceba6f
·
verified ·
1 Parent(s): 4384c59

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py CHANGED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import tensorflow as tf
4
+ from PIL import Image, ImageOps
5
+
6
+ model = tf.keras.models.load_model("model.keras")
7
+
8
+ st.title(" Handwritten Digit Detection")
9
+ st.write("Upload an image of a digit (28x28 grayscale preferred).")
10
+
11
+ uploaded_file = st.file_uploader("Choose an image...", type=["png", "jpg", "jpeg"])
12
+
13
+ if uploaded_file is not None:
14
+ image = Image.open(uploaded_file).convert('L') # Convert to grayscale
15
+ image = ImageOps.invert(image)
16
+ image = image.resize((28, 28))
17
+ img_array = np.array(image).reshape(1, 28, 28, 1) / 255.0
18
+
19
+ st.image(image, caption="Processed Input", width=150)
20
+ pred = model.predict(img_array)
21
+ st.write(f"### Predicted Digit: `{np.argmax(pred)}`")