| import streamlit as st |
| import pandas as pd |
| import numpy as np |
| import joblib |
| from PIL import Image |
| import os |
|
|
|
|
| |
| |
| |
| BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |
| model_path = os.path.join(BASE_DIR, "digit_model.pkl") |
|
|
| model = joblib.load(model_path) |
|
|
| |
| |
| |
| 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") |
|
|
| |
| |
| |
| 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}") |