Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -83,34 +83,58 @@ def process_live_frame(frame):
|
|
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 |
-
# ---
|
90 |
-
|
91 |
-
|
92 |
-
gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
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 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
|
113 |
# --- Launch the App ---
|
114 |
-
# REMOVED: The 'if __name__ == "__main__":' block.
|
115 |
-
# Hugging Face will run this file as a module and needs to find the 'app' object.
|
116 |
app.launch(debug=True)
|
|
|
83 |
else:
|
84 |
alerter.reset_alert()
|
85 |
|
|
|
86 |
return processed_frame, status_text, audio_output
|
87 |
|
88 |
+
# --- UI Definition for the Live Detection Page ---
|
89 |
+
def create_live_detection_page():
|
90 |
+
"""Builds the Gradio UI components for the live detection tab."""
|
91 |
+
with gr.Blocks(theme=gr.themes.Default(primary_hue="blue", secondary_hue="blue")) as live_detection_page:
|
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 |
+
webcam_input.stream(
|
103 |
+
fn=process_live_frame,
|
104 |
+
inputs=[webcam_input],
|
105 |
+
outputs=[processed_output, status_output, audio_alert_output]
|
106 |
+
)
|
107 |
+
return live_detection_page
|
|
|
|
|
|
|
|
|
|
|
108 |
|
109 |
+
# --- UI Definition for the Home Page ---
|
110 |
+
def create_home_page():
|
111 |
+
"""Builds the Gradio UI components for the home/welcome tab."""
|
112 |
+
with gr.Blocks(theme=gr.themes.Default(primary_hue="blue", secondary_hue="blue")) as home_page:
|
113 |
+
gr.Markdown(
|
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 |
app.launch(debug=True)
|