| import streamlit as st | |
| import pandas as pd | |
| import numpy as np | |
| import joblib | |
| from PIL import Image | |
| import os | |
| # ====================== | |
| # LOAD MODEL | |
| # ====================== | |
| model = joblib.load("digit_model.pkl") | |
| # ====================== | |
| # PAGE CONFIG | |
| # ====================== | |
| st.set_page_config( | |
| page_title="Digit Recognizer", | |
| page_icon="🔢", | |
| layout="centered" | |
| ) | |
| st.title("🔢 Handwritten Digit Recognizer") | |
| st.write("Upload a 28x28 image of a digit to get prediction") | |
| # ====================== | |
| # IMAGE UPLOAD | |
| # ====================== | |
| uploaded_file = st.file_uploader("Upload Digit Image", type=["png", "jpg", "jpeg"]) | |
| if uploaded_file is not None: | |
| image = Image.open(uploaded_file).convert("L") | |
| image = image.resize((28, 28)) | |
| st.image(image, caption="Processed Image", width=150) | |
| img_array = np.array(image) | |
| img_array = img_array.reshape(1, 784) | |
| prediction = model.predict(img_array)[0] | |
| st.subheader("Prediction") | |
| st.success(f"Predicted Digit: {prediction}") |