Spaces:
Sleeping
Sleeping
Added webcam snapshot support with Blocks interface
Browse files- Switch to gr.Blocks for better component control
- Add webcam as input source alongside upload
- Add detection button for user interaction
- Improve error handling for invalid inputs
README.md
CHANGED
|
@@ -39,12 +39,22 @@ uv run python app.py
|
|
| 39 |
|
| 40 |
The application will be available at `http://localhots:7860`
|
| 41 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
## Technical Stack
|
| 44 |
|
| 45 |
- **Hand Detection**: MediaPipe Hands (v0.10.9)
|
| 46 |
- **Classification**: Rule-based finger extension analysis
|
| 47 |
- **Frontend**: Gradio
|
| 48 |
-
- **Image Processing**: OpenCV
|
| 49 |
- **Package Management**: UV for reproducible builds
|
| 50 |
---
|
|
|
|
| 39 |
|
| 40 |
The application will be available at `http://localhots:7860`
|
| 41 |
```
|
| 42 |
+
## Testing
|
| 43 |
+
|
| 44 |
+
**Stop server:** `Ctrl+C`
|
| 45 |
+
```bash
|
| 46 |
+
# To kill previous instances of the run:
|
| 47 |
+
pkill -f "app.py" && sleep 1 && ps aux | grep "app.py" | grep -v grep
|
| 48 |
+
|
| 49 |
+
# Run the application
|
| 50 |
+
uv run python app.py
|
| 51 |
+
```
|
| 52 |
|
| 53 |
## Technical Stack
|
| 54 |
|
| 55 |
- **Hand Detection**: MediaPipe Hands (v0.10.9)
|
| 56 |
- **Classification**: Rule-based finger extension analysis
|
| 57 |
- **Frontend**: Gradio
|
| 58 |
+
- **Image Processing**: OpenCV, NumPy, CNN (TBD)
|
| 59 |
- **Package Management**: UV for reproducible builds
|
| 60 |
---
|
app.py
CHANGED
|
@@ -7,8 +7,8 @@ detector = ASLDetector()
|
|
| 7 |
|
| 8 |
def detect_asl(image):
|
| 9 |
"""Process image and detect ASL gesture."""
|
| 10 |
-
if image is None:
|
| 11 |
-
return None, "Please provide an image"
|
| 12 |
|
| 13 |
# Convert to RGB if needed
|
| 14 |
if len(image.shape) == 2:
|
|
@@ -30,15 +30,9 @@ def detect_asl(image):
|
|
| 30 |
return annotated_image, result
|
| 31 |
|
| 32 |
# Create Gradio interface
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
outputs=[
|
| 37 |
-
gr.Image(label="Detected Hand Landmarks"),
|
| 38 |
-
gr.Textbox(label="Detection Result", lines=3)
|
| 39 |
-
],
|
| 40 |
-
title="ASL Hand Detection System",
|
| 41 |
-
description="""
|
| 42 |
American Sign Language hand gesture detection using MediaPipe.
|
| 43 |
|
| 44 |
**Supported Gestures:**
|
|
@@ -47,11 +41,27 @@ demo = gr.Interface(
|
|
| 47 |
- B: All fingers extended, thumb tucked
|
| 48 |
- 1: Index finger only extended
|
| 49 |
- W: Index, middle, and ring fingers extended
|
|
|
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
if __name__ == "__main__":
|
| 57 |
demo.launch()
|
|
|
|
| 7 |
|
| 8 |
def detect_asl(image):
|
| 9 |
"""Process image and detect ASL gesture."""
|
| 10 |
+
if image is None or not isinstance(image, np.ndarray):
|
| 11 |
+
return None, "Please provide an image (use Upload or capture from Webcam)"
|
| 12 |
|
| 13 |
# Convert to RGB if needed
|
| 14 |
if len(image.shape) == 2:
|
|
|
|
| 30 |
return annotated_image, result
|
| 31 |
|
| 32 |
# Create Gradio interface
|
| 33 |
+
with gr.Blocks(title="ASL Hand Detection System") as demo:
|
| 34 |
+
gr.Markdown("""
|
| 35 |
+
# ASL Hand Detection System
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
American Sign Language hand gesture detection using MediaPipe.
|
| 37 |
|
| 38 |
**Supported Gestures:**
|
|
|
|
| 41 |
- B: All fingers extended, thumb tucked
|
| 42 |
- 1: Index finger only extended
|
| 43 |
- W: Index, middle, and ring fingers extended
|
| 44 |
+
""")
|
| 45 |
|
| 46 |
+
with gr.Row():
|
| 47 |
+
with gr.Column():
|
| 48 |
+
input_image = gr.Image(
|
| 49 |
+
sources=["upload", "webcam"],
|
| 50 |
+
type="numpy",
|
| 51 |
+
label="Input Image",
|
| 52 |
+
interactive=True
|
| 53 |
+
)
|
| 54 |
+
submit_btn = gr.Button("Detect ASL Gesture", variant="primary")
|
| 55 |
+
|
| 56 |
+
with gr.Column():
|
| 57 |
+
output_image = gr.Image(label="Detected Hand Landmarks")
|
| 58 |
+
output_text = gr.Textbox(label="Detection Result", lines=3)
|
| 59 |
+
|
| 60 |
+
submit_btn.click(
|
| 61 |
+
fn=detect_asl,
|
| 62 |
+
inputs=input_image,
|
| 63 |
+
outputs=[output_image, output_text]
|
| 64 |
+
)
|
| 65 |
|
| 66 |
if __name__ == "__main__":
|
| 67 |
demo.launch()
|