PARMESHWAR2's picture
Rename Unconfirmed 342298.crdownload to app.py
f90737a verified
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()