File size: 1,030 Bytes
c995266
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import numpy as np
import tensorflow as tf
import cv2

# Load model
model = tf.keras.models.load_model("sign_language_model (1).h5")

# A-Z excluding J and Z
letters = [chr(i) for i in range(65, 91) if chr(i) not in ['J', 'Z']]

def predict_sign_language(image):
    gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
    resized = cv2.resize(gray, (28, 28))
    normalized = resized / 255.0
    reshaped = normalized.reshape(1, 28, 28, 1)
    prediction = model.predict(reshaped)
    pred_index = np.argmax(prediction)
    predicted_letter = letters[pred_index]
    confidence = float(np.max(prediction))
    return f"{predicted_letter} (Confidence: {confidence:.2f})"

image_input = gr.Image(type="numpy", sources=["webcam", "upload"], label="Show a Hand Sign")

gr.Interface(
    fn=predict_sign_language,
    inputs=image_input,
    outputs="text",
    title="🤟 Sign Language Recognizer",
    description="Use your webcam or upload an image of a hand sign (A-Z, except J & Z) to see prediction."
).launch()