Spaces:
Sleeping
Sleeping
Add tabbed interface with snapshot, upload, and streaming modes
Browse files- Create three tabs for different input methods
- Implement live streaming with real-time detection
- Separate UI components for each mode
- Improve UX with dedicated interfaces per mode
- Added graceful kill option
app.py
CHANGED
|
@@ -29,7 +29,8 @@ def detect_asl(image):
|
|
| 29 |
|
| 30 |
return annotated_image, result
|
| 31 |
|
| 32 |
-
|
|
|
|
| 33 |
with gr.Blocks(title="ASL Hand Detection System") as demo:
|
| 34 |
gr.Markdown("""
|
| 35 |
# ASL Hand Detection System
|
|
@@ -43,25 +44,75 @@ with gr.Blocks(title="ASL Hand Detection System") as demo:
|
|
| 43 |
- W: Index, middle, and ring fingers extended
|
| 44 |
""")
|
| 45 |
|
| 46 |
-
with gr.
|
| 47 |
-
with gr.
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
)
|
| 54 |
-
submit_btn = gr.Button("Detect ASL Gesture", variant="primary")
|
| 55 |
|
| 56 |
-
with gr.
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
if __name__ == "__main__":
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
return annotated_image, result
|
| 31 |
|
| 32 |
+
|
| 33 |
+
# Create Gradio interface with tabs
|
| 34 |
with gr.Blocks(title="ASL Hand Detection System") as demo:
|
| 35 |
gr.Markdown("""
|
| 36 |
# ASL Hand Detection System
|
|
|
|
| 44 |
- W: Index, middle, and ring fingers extended
|
| 45 |
""")
|
| 46 |
|
| 47 |
+
with gr.Tabs():
|
| 48 |
+
with gr.Tab("Take a Picture"):
|
| 49 |
+
with gr.Row():
|
| 50 |
+
with gr.Column():
|
| 51 |
+
webcam_input = gr.Image(
|
| 52 |
+
sources=["webcam"],
|
| 53 |
+
type="numpy",
|
| 54 |
+
label="Webcam",
|
| 55 |
+
interactive=True
|
| 56 |
+
)
|
| 57 |
+
webcam_btn = gr.Button("Detect Gesture", variant="primary")
|
| 58 |
+
|
| 59 |
+
with gr.Column():
|
| 60 |
+
webcam_output = gr.Image(label="Detected Hand Landmarks")
|
| 61 |
+
webcam_result = gr.Textbox(label="Detection Result", lines=3)
|
| 62 |
+
|
| 63 |
+
webcam_btn.click(
|
| 64 |
+
fn=detect_asl,
|
| 65 |
+
inputs=webcam_input,
|
| 66 |
+
outputs=[webcam_output, webcam_result]
|
| 67 |
)
|
|
|
|
| 68 |
|
| 69 |
+
with gr.Tab("Upload Image"):
|
| 70 |
+
with gr.Row():
|
| 71 |
+
with gr.Column():
|
| 72 |
+
upload_input = gr.Image(
|
| 73 |
+
sources=["upload"],
|
| 74 |
+
type="numpy",
|
| 75 |
+
label="Upload Image",
|
| 76 |
+
interactive=True
|
| 77 |
+
)
|
| 78 |
+
upload_btn = gr.Button("Detect Gesture", variant="primary")
|
| 79 |
|
| 80 |
+
with gr.Column():
|
| 81 |
+
upload_output = gr.Image(label="Detected Hand Landmarks")
|
| 82 |
+
upload_result = gr.Textbox(label="Detection Result", lines=3)
|
| 83 |
+
|
| 84 |
+
upload_btn.click(
|
| 85 |
+
fn=detect_asl,
|
| 86 |
+
inputs=upload_input,
|
| 87 |
+
outputs=[upload_output, upload_result]
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
with gr.Tab("Live Streaming"):
|
| 91 |
+
with gr.Row():
|
| 92 |
+
with gr.Column():
|
| 93 |
+
stream_input = gr.Image(
|
| 94 |
+
sources=["webcam"],
|
| 95 |
+
type="numpy",
|
| 96 |
+
label="Live Webcam Feed",
|
| 97 |
+
interactive=True,
|
| 98 |
+
streaming=True
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
with gr.Column():
|
| 102 |
+
stream_output = gr.Image(label="Detected Hand Landmarks")
|
| 103 |
+
stream_result = gr.Textbox(label="Detection Result", lines=3)
|
| 104 |
+
|
| 105 |
+
stream_input.stream(
|
| 106 |
+
fn=detect_asl,
|
| 107 |
+
inputs=stream_input,
|
| 108 |
+
outputs=[stream_output, stream_result]
|
| 109 |
+
)
|
| 110 |
|
| 111 |
if __name__ == "__main__":
|
| 112 |
+
try:
|
| 113 |
+
print("[INFO] Starting ASL Hand Detection System...")
|
| 114 |
+
demo.launch()
|
| 115 |
+
except KeyboardInterrupt:
|
| 116 |
+
print("\n[INFO] Shutting down gracefully...")
|
| 117 |
+
finally:
|
| 118 |
+
print("[INFO] Application stopped")
|