Jainam117's picture
Update app.py
ac4cdc6 verified
import streamlit as st
from tensorflow.keras.models import load_model
from huggingface_hub import from_pretrained_keras
from PIL import Image
import numpy as np
import tensorflow as tf
@st.cache_resource
def load_model_h5():
model_path = hf_hub_download(repo_id="Jainam117/Sign_Langauge_digit_classification",
filename="sign_lan_digit_model.h5")
model = load_model(model_path)
return model
def preprocess_image(image):
image = image.convert("L")
image = image.resize((224, 224)) # Resize to 224x224, which the model expects
image_array = np.array(image)
image_array = image_array / 255.0
image_array = np.expand_dims(image_array, axis=-1)
image_array = np.expand_dims(image_array, axis=0)
return image_array
def classify_image(model, image_array):
predictions = model.predict(image_array)
predicted_label = np.argmax(predictions, axis=1)[0]
return predicted_label
st.title("Sign Language Digit Classification")
st.write("Upload an image of a hand showing a digit, and the model will classify the digit.")
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
if uploaded_file is not None:
image = Image.open(uploaded_file)
st.image(image, caption="Uploaded Image", use_column_width=True)
model = load_model()
preprocessed_image = preprocess_image(image)
predicted_digit = classify_image(model, preprocessed_image)
st.write(f"Predicted Digit: {predicted_digit}")