Upload 4 files
Browse files- .gitattributes +1 -0
- app.py +130 -0
- asl_model.keras +3 -0
- class_names.npy +3 -0
- requirements.txt +0 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
asl_model.keras filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
+
import tensorflow as tf
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import pyttsx3
|
| 6 |
+
|
| 7 |
+
# ------------------- CONFIG -------------------
|
| 8 |
+
MODEL_PATH = "asl_model.keras" # or "asl_model.h5"
|
| 9 |
+
CLASS_NAMES_PATH = "class_names.npy"
|
| 10 |
+
IMG_HEIGHT, IMG_WIDTH = 64, 64
|
| 11 |
+
|
| 12 |
+
# ------------------- LOAD MODEL -------------------
|
| 13 |
+
@st.cache_resource
|
| 14 |
+
def load_model():
|
| 15 |
+
return tf.keras.models.load_model(MODEL_PATH)
|
| 16 |
+
|
| 17 |
+
@st.cache_data
|
| 18 |
+
def load_class_names():
|
| 19 |
+
return np.load(CLASS_NAMES_PATH)
|
| 20 |
+
|
| 21 |
+
model = load_model()
|
| 22 |
+
class_names = load_class_names()
|
| 23 |
+
|
| 24 |
+
# ------------------- SPEAK FUNCTION -------------------
|
| 25 |
+
def speak(text):
|
| 26 |
+
engine = pyttsx3.init()
|
| 27 |
+
voices = engine.getProperty('voices')
|
| 28 |
+
engine.setProperty('voice', voices[0].id) # Change to voices[1].id for female
|
| 29 |
+
engine.setProperty('rate', 150)
|
| 30 |
+
engine.setProperty('volume', 1.0)
|
| 31 |
+
engine.say(text)
|
| 32 |
+
engine.runAndWait()
|
| 33 |
+
|
| 34 |
+
# ------------------- PREDICTION FUNCTION -------------------
|
| 35 |
+
def predict(image):
|
| 36 |
+
image = image.resize((IMG_WIDTH, IMG_HEIGHT))
|
| 37 |
+
img_array = tf.keras.utils.img_to_array(image)
|
| 38 |
+
img_array = tf.expand_dims(img_array, 0) / 255.0
|
| 39 |
+
prediction = model.predict(img_array)
|
| 40 |
+
index = np.argmax(prediction[0])
|
| 41 |
+
label = class_names[index]
|
| 42 |
+
confidence = np.max(prediction[0])
|
| 43 |
+
return label, confidence
|
| 44 |
+
|
| 45 |
+
# ------------------- STREAMLIT UI -------------------
|
| 46 |
+
st.set_page_config(page_title="ASL Sign Classifier", page_icon="๐ค", layout="centered")
|
| 47 |
+
|
| 48 |
+
# ---------- CSS Styling ----------
|
| 49 |
+
st.markdown("""
|
| 50 |
+
<style>
|
| 51 |
+
.main-title {
|
| 52 |
+
font-size: 2.8em;
|
| 53 |
+
text-align: center;
|
| 54 |
+
font-weight: bold;
|
| 55 |
+
margin-bottom: 10px;
|
| 56 |
+
color: #333;
|
| 57 |
+
}
|
| 58 |
+
.description {
|
| 59 |
+
text-align: center;
|
| 60 |
+
font-size: 1.1rem;
|
| 61 |
+
margin-bottom: 20px;
|
| 62 |
+
color: #555;
|
| 63 |
+
}
|
| 64 |
+
.prediction-box {
|
| 65 |
+
background-color: #f0f2f6;
|
| 66 |
+
padding: 1.5rem;
|
| 67 |
+
border-radius: 12px;
|
| 68 |
+
text-align: center;
|
| 69 |
+
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
|
| 70 |
+
font-size: 1.2rem;
|
| 71 |
+
color: #000;
|
| 72 |
+
}
|
| 73 |
+
.stButton > button {
|
| 74 |
+
border-radius: 8px;
|
| 75 |
+
padding: 0.6rem 1.2rem;
|
| 76 |
+
font-weight: 500;
|
| 77 |
+
}
|
| 78 |
+
</style>
|
| 79 |
+
""", unsafe_allow_html=True)
|
| 80 |
+
|
| 81 |
+
# ---------- Title ----------
|
| 82 |
+
st.markdown('<div class="main-title">๐ค ASL Sign Language Classifier</div>', unsafe_allow_html=True)
|
| 83 |
+
st.markdown('<div class="description">Upload an image of an ASL hand sign and get an instant spoken prediction!</div>', unsafe_allow_html=True)
|
| 84 |
+
|
| 85 |
+
# ---------- File Upload ----------
|
| 86 |
+
uploaded_file = st.file_uploader("๐ Upload ASL Image", type=["jpg", "png", "jpeg"])
|
| 87 |
+
|
| 88 |
+
# ---------- Prediction Flow ----------
|
| 89 |
+
if uploaded_file is not None:
|
| 90 |
+
image = Image.open(uploaded_file)
|
| 91 |
+
st.image(image, caption="๐ผ Uploaded Image", use_column_width=False, width=250)
|
| 92 |
+
|
| 93 |
+
if st.button("๐ฏ Predict Sign"):
|
| 94 |
+
with st.spinner("Analyzing the sign..."):
|
| 95 |
+
label, confidence = predict(image)
|
| 96 |
+
|
| 97 |
+
# Handle special signs
|
| 98 |
+
spoken_label = str(label)
|
| 99 |
+
if spoken_label == "SPACE":
|
| 100 |
+
spoken_label = "space"
|
| 101 |
+
elif spoken_label == "DELETE":
|
| 102 |
+
spoken_label = "delete"
|
| 103 |
+
elif spoken_label == "NOTHING":
|
| 104 |
+
spoken_label = "nothing"
|
| 105 |
+
|
| 106 |
+
# Save prediction
|
| 107 |
+
st.session_state['prediction'] = {
|
| 108 |
+
'label': label,
|
| 109 |
+
'confidence': confidence
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
# Automatically speak
|
| 113 |
+
speak(spoken_label)
|
| 114 |
+
|
| 115 |
+
# ---------- Show Result ----------
|
| 116 |
+
if 'prediction' in st.session_state:
|
| 117 |
+
label = st.session_state['prediction']['label']
|
| 118 |
+
confidence = st.session_state['prediction']['confidence']
|
| 119 |
+
|
| 120 |
+
st.markdown(f"""
|
| 121 |
+
<div class="prediction-box">
|
| 122 |
+
โ
<strong>Predicted Sign:</strong>
|
| 123 |
+
<span style="font-size: 1.5rem; font-weight: bold;">{label}</span><br><br>
|
| 124 |
+
๐ <strong>Confidence:</strong> {confidence*100:.2f}%
|
| 125 |
+
</div>
|
| 126 |
+
""", unsafe_allow_html=True)
|
| 127 |
+
|
| 128 |
+
# Optional: Repeat audio
|
| 129 |
+
if st.button("๐ Repeat Prediction"):
|
| 130 |
+
speak(str(label))
|
asl_model.keras
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:38a2c2b2186178bbbc3cda9d5fb3666dbf2de900f2efeab0dcf93959ee0ebef0
|
| 3 |
+
size 8292972
|
class_names.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dcd5dd14b81322e3811825e0a77c0b649ad8d0be4ba76cce632ba8f13fb8f37c
|
| 3 |
+
size 940
|
requirements.txt
ADDED
|
Binary file (136 Bytes). View file
|
|
|