DSatishchandra commited on
Commit
a3ecb21
Β·
verified Β·
1 Parent(s): 9a5a939

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +88 -29
app.py CHANGED
@@ -43,7 +43,7 @@ def live_feed_generator(video_type, confidence_threshold=0.9):
43
  video_path = VIDEO_PATHS.get(video_type)
44
 
45
  if not video_path or not os.path.exists(video_path):
46
- yield gr.update(value="Video file not found."), None, None, None, None, None
47
  return
48
 
49
  cap = cv2.VideoCapture(video_path)
@@ -114,21 +114,26 @@ def live_feed_generator(video_type, confidence_threshold=0.9):
114
  box = detection["box"]
115
  coords = f"[{box['xmin']},{box['ymin']},{box['xmax']},{box['ymax']}]"
116
  metrics.append(coords)
117
- metrics_str = f"anomalies: {metrics}, total_detected: {state.total_detected}"
118
 
119
- # Generate detection trend plot
 
120
  plt.figure(figsize=(4, 2))
121
- plt.plot(list(state.anomaly_history), marker='o')
122
- plt.title("Anomalies Over Time")
123
- plt.xlabel("Frame")
124
- plt.ylabel("Count")
125
- plt.grid(True)
 
126
  trend_plot = plt.gcf()
127
  plt.close()
128
 
129
  # Generate anomaly types summary
130
  anomaly_types_str = "\n".join([f"{k}: {v}" for k, v in state.anomaly_types.items()])
131
 
 
 
 
132
  # Yield updated UI components
133
  yield (
134
  gr.update(value=annotated_frame_rgb), # Live Video Feed
@@ -136,7 +141,8 @@ def live_feed_generator(video_type, confidence_threshold=0.9):
136
  gr.update(value="\n".join(state.logs)), # Live Logs
137
  gr.update(value=trend_plot), # Detection Trend
138
  gr.update(value=anomaly_types_str), # Anomaly Types
139
- gr.update(value=list(state.captured_events)) # Captured Events
 
140
  )
141
 
142
  # Simulate real-time by sleeping between frames
@@ -144,33 +150,86 @@ def live_feed_generator(video_type, confidence_threshold=0.9):
144
 
145
  cap.release()
146
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  # Gradio Interface
148
- with gr.Blocks() as demo:
149
- gr.Markdown("# Solar Panel Monitoring System")
 
 
150
  with gr.Row():
151
- with gr.Column():
152
- video_type = gr.Dropdown(
153
- choices=["Day Feed", "Night Feed", "Thermal Feed", "Shadow/Dust Feed"],
154
- label="Select Drone Feed",
155
- value="Thermal Feed"
 
 
 
 
 
 
 
 
 
156
  )
157
- confidence_threshold = gr.Slider(0.5, 1.0, value=0.9, label="Confidence Threshold")
158
- start_button = gr.Button("Start Live Feed")
159
- with gr.Column():
160
- live_feed = gr.Image(label="Live Video Feed", streaming=True)
161
- with gr.Row():
162
- with gr.Column():
163
- live_metrics = gr.Textbox(label="Live Metrics")
164
- live_logs = gr.Textbox(label="Live Logs")
165
- with gr.Column():
166
- detection_trend = gr.Plot(label="Detection Trend")
167
- anomaly_types = gr.Textbox(label="Anomaly Types")
168
- captured_events = gr.Gallery(label="Captured Events (Last 5)")
169
 
170
  start_button.click(
171
  fn=live_feed_generator,
172
  inputs=[video_type, confidence_threshold],
173
- outputs=[live_feed, live_metrics, live_logs, detection_trend, anomaly_types, captured_events]
174
  )
175
 
176
  demo.launch()
 
43
  video_path = VIDEO_PATHS.get(video_type)
44
 
45
  if not video_path or not os.path.exists(video_path):
46
+ yield gr.update(value="Video file not found."), None, None, None, None, None, None
47
  return
48
 
49
  cap = cv2.VideoCapture(video_path)
 
114
  box = detection["box"]
115
  coords = f"[{box['xmin']},{box['ymin']},{box['xmax']},{box['ymax']}]"
116
  metrics.append(coords)
117
+ metrics_str = f"Coordinates: {metrics}\nTotal Detected: {state.total_detected}"
118
 
119
+ # Generate detection trend plot with dark theme
120
+ plt.style.use('dark_background')
121
  plt.figure(figsize=(4, 2))
122
+ plt.plot(list(state.anomaly_history), marker='o', color='yellow')
123
+ plt.title("Anomalies Over Time", color='white')
124
+ plt.xlabel("Frame", color='white')
125
+ plt.ylabel("Count", color='white')
126
+ plt.grid(True, color='gray')
127
+ plt.tick_params(colors='white')
128
  trend_plot = plt.gcf()
129
  plt.close()
130
 
131
  # Generate anomaly types summary
132
  anomaly_types_str = "\n".join([f"{k}: {v}" for k, v in state.anomaly_types.items()])
133
 
134
+ # Update timestamp
135
+ timestamp_str = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
136
+
137
  # Yield updated UI components
138
  yield (
139
  gr.update(value=annotated_frame_rgb), # Live Video Feed
 
141
  gr.update(value="\n".join(state.logs)), # Live Logs
142
  gr.update(value=trend_plot), # Detection Trend
143
  gr.update(value=anomaly_types_str), # Anomaly Types
144
+ gr.update(value=list(state.captured_events)), # Captured Events
145
+ gr.update(value=timestamp_str) # Timestamp
146
  )
147
 
148
  # Simulate real-time by sleeping between frames
 
150
 
151
  cap.release()
152
 
153
+ # Custom CSS for dark theme and styling
154
+ custom_css = """
155
+ body, .gradio-container {
156
+ background-color: #1a1a1a !important;
157
+ color: white !important;
158
+ font-family: Arial, sans-serif !important;
159
+ }
160
+ h1, h2, h3, label {
161
+ color: white !important;
162
+ font-weight: bold !important;
163
+ }
164
+ .gradio-row, .gradio-column {
165
+ background-color: #2b2b2b !important;
166
+ border-radius: 8px !important;
167
+ padding: 10px !important;
168
+ margin: 5px !important;
169
+ }
170
+ #live-feed {
171
+ border: 2px solid #444 !important;
172
+ border-radius: 8px !important;
173
+ }
174
+ #live-metrics, #live-logs, #anomaly-types {
175
+ background-color: #333 !important;
176
+ color: white !important;
177
+ border: 1px solid #555 !important;
178
+ border-radius: 8px !important;
179
+ padding: 10px !important;
180
+ height: 100px !important;
181
+ overflow-y: auto !important;
182
+ }
183
+ #detection-trend, #captured-events {
184
+ background-color: #333 !important;
185
+ border: 1px solid #555 !important;
186
+ border-radius: 8px !important;
187
+ padding: 10px !important;
188
+ }
189
+ #status-indicator {
190
+ color: #00ff00 !important;
191
+ font-size: 14px !important;
192
+ }
193
+ #timestamp {
194
+ font-size: 16px !important;
195
+ color: #cccccc !important;
196
+ }
197
+ """
198
+
199
  # Gradio Interface
200
+ with gr.Blocks(css=custom_css) as demo:
201
+ gr.Markdown("# Fault Detection")
202
+ timestamp = gr.Textbox(label="", value=datetime.now().strftime("%Y-%m-%d %H:%M:%S"), elem_id="timestamp")
203
+
204
  with gr.Row():
205
+ # Left Panel: Live Feed and Controls
206
+ with gr.Column(scale=7):
207
+ with gr.Row():
208
+ video_type = gr.Dropdown(
209
+ choices=["Day Feed", "Night Feed", "Thermal Feed", "Shadow/Dust Feed"],
210
+ label="Select Drone Feed",
211
+ value="Thermal Feed"
212
+ )
213
+ confidence_threshold = gr.Slider(0.5, 1.0, value=0.9, label="Confidence Threshold")
214
+ start_button = gr.Button("Start Live Feed")
215
+ live_feed = gr.Image(label="Live Video Feed", streaming=True, elem_id="live-feed")
216
+ status_indicator = gr.HTML(
217
+ '<p id="status-indicator">Status: <span style="color: green;">Running</span> β€’</p>',
218
+ label=""
219
  )
220
+
221
+ # Right Panel: Analytics
222
+ with gr.Column(scale=3):
223
+ live_metrics = gr.Textbox(label="Live Metrics", elem_id="live-metrics")
224
+ live_logs = gr.Textbox(label="Live Logs", elem_id="live-logs")
225
+ detection_trend = gr.Plot(label="Detection Trend", elem_id="detection-trend")
226
+ anomaly_types = gr.Textbox(label="Anomaly Types", elem_id="anomaly-types")
227
+ captured_events = gr.Gallery(label="Captured Events (Last 5)", elem_id="captured-events")
 
 
 
 
228
 
229
  start_button.click(
230
  fn=live_feed_generator,
231
  inputs=[video_type, confidence_threshold],
232
+ outputs=[live_feed, live_metrics, live_logs, detection_trend, anomaly_types, captured_events, timestamp]
233
  )
234
 
235
  demo.launch()