import streamlit as st import numpy as np import tensorflow as tf from PIL import Image import pyttsx3 # ------------------- CONFIG ------------------- MODEL_PATH = "asl_model.keras" # or "asl_model.h5" CLASS_NAMES_PATH = "class_names.npy" IMG_HEIGHT, IMG_WIDTH = 64, 64 # ------------------- LOAD MODEL ------------------- @st.cache_resource def load_model(): return tf.keras.models.load_model(MODEL_PATH) @st.cache_data def load_class_names(): return np.load(CLASS_NAMES_PATH) model = load_model() class_names = load_class_names() # ------------------- SPEAK FUNCTION ------------------- def speak(text): engine = pyttsx3.init() voices = engine.getProperty('voices') engine.setProperty('voice', voices[0].id) # Change to voices[1].id for female engine.setProperty('rate', 150) engine.setProperty('volume', 1.0) engine.say(text) engine.runAndWait() # ------------------- PREDICTION FUNCTION ------------------- def predict(image): image = image.resize((IMG_WIDTH, IMG_HEIGHT)) img_array = tf.keras.utils.img_to_array(image) img_array = tf.expand_dims(img_array, 0) / 255.0 prediction = model.predict(img_array) index = np.argmax(prediction[0]) label = class_names[index] confidence = np.max(prediction[0]) return label, confidence # ------------------- STREAMLIT UI ------------------- st.set_page_config(page_title="ASL Sign Classifier", page_icon="🤟", layout="centered") # ---------- CSS Styling ---------- st.markdown(""" """, unsafe_allow_html=True) # ---------- Title ---------- st.markdown('