File size: 1,528 Bytes
1e44634
ac4cdc6
1e44634
 
 
 
 
 
ac4cdc6
 
 
 
1e44634
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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}")