|
|
import gradio as gr |
|
|
import numpy as np |
|
|
import tensorflow as tf |
|
|
import cv2 |
|
|
|
|
|
|
|
|
model = tf.keras.models.load_model("sign_language_model (1).h5") |
|
|
|
|
|
|
|
|
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() |
|
|
|