drixo commited on
Commit
a2ea39a
·
verified ·
1 Parent(s): 4ba6e36

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -68
app.py CHANGED
@@ -1,69 +1 @@
1
- import os
2
- import random
3
- from PIL import Image
4
- import gradio as gr
5
 
6
- # -------------------------------
7
- # Load ASL dataset
8
- # -------------------------------
9
- dataset_path = "asl_dataset"
10
- letter_image_map = {}
11
-
12
- for letter in sorted(os.listdir(dataset_path)):
13
- letter_path = os.path.join(dataset_path, letter)
14
- if os.path.isdir(letter_path):
15
- imgs = [
16
- os.path.join(letter_path, f)
17
- for f in os.listdir(letter_path)
18
- if f.lower().endswith((".png", ".jpg", ".jpeg"))
19
- ]
20
- if imgs:
21
- letter_image_map[letter.upper()] = imgs
22
-
23
- print(f"Loaded letters: {list(letter_image_map.keys())}")
24
-
25
- # -------------------------------
26
- # Dummy recognizers
27
- # -------------------------------
28
- letters_cycle = iter(letter_image_map.keys())
29
-
30
- def next_letter(frame):
31
- """Cycle through letters for practice."""
32
- try:
33
- letter = next(letters_cycle)
34
- except StopIteration:
35
- return "Done!", None
36
- img_path = random.choice(letter_image_map[letter])
37
- return f"Letter: {letter}", Image.open(img_path)
38
-
39
- def recognize_audio(audio_file):
40
- """Dummy audio recognition."""
41
- if audio_file is None:
42
- return "Say a letter...", None
43
- letter = random.choice(list(letter_image_map.keys()))
44
- img_path = random.choice(letter_image_map[letter])
45
- return f"You said: {letter}", Image.open(img_path)
46
-
47
- # -------------------------------
48
- # Gradio UI (v5 syntax)
49
- # -------------------------------
50
- with gr.Blocks() as demo:
51
- gr.Markdown("# 🧠 Hands-Free ASL Helper — Webcam + Voice")
52
-
53
- # Webcam section
54
- gr.Markdown("## Webcam Practice (Auto-cycle)")
55
- webcam = gr.Image(label="Camera Feed", type="pil") # no 'source' in v5
56
- webcam_status = gr.Textbox(label="Detected Letter", interactive=False)
57
- webcam_output = gr.Image(label="ASL Sign")
58
-
59
- # Update every 1s for auto-cycle
60
- webcam.change(next_letter, inputs=webcam, outputs=[webcam_status, webcam_output])
61
-
62
- # Voice section
63
- gr.Markdown("## Voice Detection (Say a letter)")
64
- audio_input = gr.Audio(source="microphone", type="filepath", label="Speak a Letter")
65
- audio_status = gr.Textbox(label="Spoken Letter", interactive=False)
66
- audio_output = gr.Image(label="ASL Sign")
67
- audio_input.change(recognize_audio, inputs=audio_input, outputs=[audio_status, audio_output])
68
-
69
- demo.launch()
 
 
 
 
 
1