Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -83,58 +83,33 @@ def process_live_frame(frame):
|
|
83 |
else:
|
84 |
alerter.reset_alert()
|
85 |
|
|
|
86 |
return processed_frame, status_text, audio_output
|
87 |
|
88 |
-
# --- UI Definition
|
89 |
-
|
90 |
-
"
|
91 |
-
|
92 |
-
gr.Markdown("A live test using Gradio's webcam component.")
|
93 |
-
with gr.Row():
|
94 |
-
with gr.Column():
|
95 |
-
webcam_input = gr.Image(sources=["webcam"], streaming=True, label="Live Camera Feed")
|
96 |
-
with gr.Column():
|
97 |
-
processed_output = gr.Image(label="Processed Feed")
|
98 |
-
status_output = gr.Textbox(label="Live Status", lines=3, interactive=False)
|
99 |
-
# Audio player is now visible for debugging and user feedback.
|
100 |
-
audio_alert_output = gr.Audio(autoplay=True, visible=True, label="Alert Sound")
|
101 |
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
)
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
108 |
|
109 |
-
#
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
<div align="center">
|
116 |
-
<img src="https://em-content.zobj.net/source/samsung/380/automobile_1f697.png" alt="Car Emoji" width="100"/>
|
117 |
-
<h1>Welcome to Drive Paddy!</h1>
|
118 |
-
<p><strong>Your Drowsiness Detection Assistant</strong></p>
|
119 |
-
</div>
|
120 |
-
|
121 |
-
---
|
122 |
-
|
123 |
-
### How It Works
|
124 |
-
This application uses your webcam to monitor for signs of drowsiness in real-time. Navigate to the **Live Detection** tab to begin.
|
125 |
-
|
126 |
-
- **Multi-Signal Analysis**: Detects eye closure, yawning, and head position.
|
127 |
-
- **AI-Powered Alerts**: Uses Gemini to generate dynamic audio warnings.
|
128 |
-
- **Live Feedback**: Provides instant visual feedback on the video stream and status panel.
|
129 |
-
"""
|
130 |
-
)
|
131 |
-
return home_page
|
132 |
-
|
133 |
-
# --- Combine Pages into a Tabbed Interface ---
|
134 |
-
app = gr.TabbedInterface(
|
135 |
-
[create_home_page(), create_live_detection_page()],
|
136 |
-
["Home", "Live Detection"]
|
137 |
-
)
|
138 |
|
139 |
# --- Launch the App ---
|
140 |
-
|
|
|
|
83 |
else:
|
84 |
alerter.reset_alert()
|
85 |
|
86 |
+
# Return all the values needed to update the UI
|
87 |
return processed_frame, status_text, audio_output
|
88 |
|
89 |
+
# --- Gradio UI Definition ---
|
90 |
+
with gr.Blocks(theme=gr.themes.Default(primary_hue="blue", secondary_hue="blue")) as app:
|
91 |
+
gr.Markdown("# 🚗 Drive Paddy - Drowsiness Detection (Gradio)")
|
92 |
+
gr.Markdown("A live test using Gradio's webcam component. This can be more stable than WebRTC in some environments.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
|
94 |
+
with gr.Row():
|
95 |
+
with gr.Column():
|
96 |
+
# Input: Live webcam feed
|
97 |
+
webcam_input = gr.Image(sources=["webcam"], streaming=True, label="Live Camera Feed")
|
98 |
+
with gr.Column():
|
99 |
+
# Output 1: Processed video feed
|
100 |
+
processed_output = gr.Image(label="Processed Feed")
|
101 |
+
# Output 2: Live status text
|
102 |
+
status_output = gr.Textbox(label="Live Status", lines=3, interactive=False)
|
103 |
+
# Output 3: Hidden audio player for alerts
|
104 |
+
audio_alert_output = gr.Audio(autoplay=True, visible=False)
|
105 |
|
106 |
+
# Link the input to the processing function and the function to the outputs
|
107 |
+
webcam_input.stream(
|
108 |
+
fn=process_live_frame,
|
109 |
+
inputs=[webcam_input],
|
110 |
+
outputs=[processed_output, status_output, audio_alert_output]
|
111 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
|
113 |
# --- Launch the App ---
|
114 |
+
if __name__ == "__main__":
|
115 |
+
app.launch(debug=True)
|