divyanshi149/Handwritten_Digit_Recognition_Streamlit
0
1import streamlit as st2import numpy as np3from PIL import Image4import tensorflow as tf5 6# Load your trained model7model = tf.keras.models.load_model("Handwritten_Digit_Recognition_Model.h5")8 9 10def main():11 st.title("Handwritten Digit Recognition System") #title of the Streamlit webpage12 13 # Allow users to upload their own image14 uploaded_file = st.file_uploader("Upload Handwritten Digit Image", type=["jpg", "jpeg", "png"])15 16 if uploaded_file is not None: #uploaded file exists17 # Display the uploaded image18 uploaded_image = Image.open(uploaded_file)19 st.image(uploaded_image, caption="Uploaded Image", use_column_width=True)20 21 #preprocess and pass the input to your model22 #similar to Gradio23 raw_image = np.array(uploaded_image)24 reshaped_image = np.reshape(raw_image, (-1, 28, 28, 1))25 prediction_raw = model.predict(reshaped_image)26 predicted_label = np.argmax(prediction_raw)27 28 # Display the predicted label29 st.write("The input digit is: ", predicted_label)30 31if __name__ == "__main__":32 main()33 