File size: 1,172 Bytes
78b2a90
3629562
 
 
78b2a90
3629562
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from tensorflow.keras.models import load_model
from PIL import Image, ImageOps
import numpy as np

model = load_model('src/sign_model.h5')

def process_image(img):
    img = img.convert('L')
    img = img.resize((28, 28))
    img = np.array(img)
    img = img / 255.0
    
    # Reshape to (1, 28, 28, 1)
    img = img.reshape(1, 28, 28, 1)
    return img

st.title("Sign Language Classification")
st.write("Upload an image of a hand sign (A-Y) and the model will predict the letter.")

file = st.file_uploader('Select an image', type=['jpg', 'jpeg', 'png'])

if file is not None:
    img = Image.open(file)
    st.image(img, caption='Uploaded Image', width=200)
    
    image = process_image(img)
    prediction = model.predict(image)
    predicted_class = np.argmax(prediction)
    
    class_names = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 
                   'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 
                   'V', 'W', 'X', 'Y']
    
    if predicted_class < len(class_names):
        result = class_names[predicted_class]
    else:
        result = str(predicted_class)

    st.write(f"Prediction: **{result}**")