Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,44 +1,128 @@
|
|
1 |
import gradio as gr
|
2 |
import cv2
|
|
|
|
|
|
|
|
|
3 |
from services.video_service import get_random_video_frame
|
|
|
4 |
from services.detection_service import detect_objects
|
5 |
from services.thermal_service import detect_thermal_anomalies
|
6 |
-
from services.overlay_service import overlay_boxes
|
7 |
|
8 |
TEMP_IMAGE_PATH = "temp.jpg"
|
9 |
|
10 |
def monitor_feed():
|
11 |
frame = get_random_video_frame()
|
12 |
if frame is None:
|
13 |
-
return None,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
cv2.imwrite(TEMP_IMAGE_PATH, frame)
|
16 |
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
|
21 |
-
|
22 |
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
def build_interface():
|
26 |
-
with gr.Blocks(
|
27 |
-
gr.Markdown("# 🚀 Solar Surveillance POC Demo")
|
28 |
with gr.Row():
|
29 |
-
image_display = gr.Image(label="
|
30 |
with gr.Column():
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
40 |
return demo
|
41 |
|
42 |
if __name__ == "__main__":
|
43 |
demo = build_interface()
|
44 |
-
demo.
|
|
|
|
1 |
import gradio as gr
|
2 |
import cv2
|
3 |
+
import os
|
4 |
+
import random
|
5 |
+
import time
|
6 |
+
|
7 |
from services.video_service import get_random_video_frame
|
8 |
+
from services.overlay_service import overlay_boxes
|
9 |
from services.detection_service import detect_objects
|
10 |
from services.thermal_service import detect_thermal_anomalies
|
|
|
11 |
|
12 |
TEMP_IMAGE_PATH = "temp.jpg"
|
13 |
|
14 |
def monitor_feed():
|
15 |
frame = get_random_video_frame()
|
16 |
if frame is None:
|
17 |
+
return None, "No frame available", 0, 0
|
18 |
+
|
19 |
+
# Save current frame
|
20 |
+
cv2.imwrite(TEMP_IMAGE_PATH, frame)
|
21 |
+
|
22 |
+
# Object detection
|
23 |
+
detections = detect_objects(TEMP_IMAGE_PATH)
|
24 |
+
|
25 |
+
# Thermal detection
|
26 |
+
thermal_detections = detect_thermal_anomalies(TEMP_IMAGE_PATH)
|
27 |
+
|
28 |
+
# Merge all detections
|
29 |
+
all_detections = detections + thermal_detections
|
30 |
+
|
31 |
+
# Overlay bounding boxes
|
32 |
+
result_image = overlay_boxes(TEMP_IMAGE_PATH, all_detections)
|
33 |
+
|
34 |
+
if result_image is not None:
|
35 |
+
cv2.imwrite(TEMP_IMAGE_PATH, result_image)
|
36 |
+
|
37 |
+
# For metric panel
|
38 |
+
anomaly_count = len([d for d in all_detections if d[4] != "normal"])
|
39 |
+
total_count = len(all_detections)
|
40 |
+
|
41 |
+
return TEMP_IMAGE_PATH, f"Detected {anomaly_count} anomalies", anomaly_count, total_count
|
42 |
|
43 |
+
def build_interface():
|
44 |
+
with gr.Blocks() as demo:
|
45 |
+
with gr.Row():
|
46 |
+
image_display = gr.Image(label="Solar Drone Monitoring", interactive=False)
|
47 |
+
with gr.Column():
|
48 |
+
anomaly_info = gr.Textbox(label="Anomaly Summary", interactive=False)
|
49 |
+
anomaly_count = gr.Number(label="Anomaly Count", interactive=False)
|
50 |
+
total_objects = gr.Number(label="Total Detections", interactive=False)
|
51 |
+
|
52 |
+
def loop_monitor():
|
53 |
+
while True:
|
54 |
+
time.sleep(1) # every 1 second
|
55 |
+
yield monitor_feed()
|
56 |
+
|
57 |
+
demo.load(loop_monitor, outputs=[image_display, anomaly_info, anomaly_count, total_objects])
|
58 |
+
|
59 |
+
return demo
|
60 |
+
|
61 |
+
if __name__ == "__main__":
|
62 |
+
demo = build_interface()
|
63 |
+
demo.queue()
|
64 |
+
demo.launch(server_name="0.0.0.0", server_port=7860, share=True)
|
65 |
+
import gradio as gr
|
66 |
+
import cv2
|
67 |
+
import os
|
68 |
+
import random
|
69 |
+
import time
|
70 |
+
|
71 |
+
from services.video_service import get_random_video_frame
|
72 |
+
from services.overlay_service import overlay_boxes
|
73 |
+
from services.detection_service import detect_objects
|
74 |
+
from services.thermal_service import detect_thermal_anomalies
|
75 |
+
|
76 |
+
TEMP_IMAGE_PATH = "temp.jpg"
|
77 |
+
|
78 |
+
def monitor_feed():
|
79 |
+
frame = get_random_video_frame()
|
80 |
+
if frame is None:
|
81 |
+
return None, "No frame available", 0, 0
|
82 |
+
|
83 |
+
# Save current frame
|
84 |
cv2.imwrite(TEMP_IMAGE_PATH, frame)
|
85 |
|
86 |
+
# Object detection
|
87 |
+
detections = detect_objects(TEMP_IMAGE_PATH)
|
88 |
+
|
89 |
+
# Thermal detection
|
90 |
+
thermal_detections = detect_thermal_anomalies(TEMP_IMAGE_PATH)
|
91 |
+
|
92 |
+
# Merge all detections
|
93 |
+
all_detections = detections + thermal_detections
|
94 |
|
95 |
+
# Overlay bounding boxes
|
96 |
+
result_image = overlay_boxes(TEMP_IMAGE_PATH, all_detections)
|
97 |
|
98 |
+
if result_image is not None:
|
99 |
+
cv2.imwrite(TEMP_IMAGE_PATH, result_image)
|
100 |
+
|
101 |
+
# For metric panel
|
102 |
+
anomaly_count = len([d for d in all_detections if d[4] != "normal"])
|
103 |
+
total_count = len(all_detections)
|
104 |
+
|
105 |
+
return TEMP_IMAGE_PATH, f"Detected {anomaly_count} anomalies", anomaly_count, total_count
|
106 |
|
107 |
def build_interface():
|
108 |
+
with gr.Blocks() as demo:
|
|
|
109 |
with gr.Row():
|
110 |
+
image_display = gr.Image(label="Solar Drone Monitoring", interactive=False)
|
111 |
with gr.Column():
|
112 |
+
anomaly_info = gr.Textbox(label="Anomaly Summary", interactive=False)
|
113 |
+
anomaly_count = gr.Number(label="Anomaly Count", interactive=False)
|
114 |
+
total_objects = gr.Number(label="Total Detections", interactive=False)
|
115 |
+
|
116 |
+
def loop_monitor():
|
117 |
+
while True:
|
118 |
+
time.sleep(1) # every 1 second
|
119 |
+
yield monitor_feed()
|
120 |
+
|
121 |
+
demo.load(loop_monitor, outputs=[image_display, anomaly_info, anomaly_count, total_objects])
|
122 |
+
|
123 |
return demo
|
124 |
|
125 |
if __name__ == "__main__":
|
126 |
demo = build_interface()
|
127 |
+
demo.queue()
|
128 |
+
demo.launch(server_name="0.0.0.0", server_port=7860, share=True)
|