d2j666 commited on
Commit
2ae3f41
·
1 Parent(s): 7f11f80

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

Files changed (1) hide show
  1. app.py +69 -18
app.py CHANGED
@@ -29,7 +29,8 @@ def detect_asl(image):
29
 
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
@@ -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.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()
 
 
 
 
 
 
 
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")