Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,67 +1,40 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
|
4 |
-
from
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
video_path =
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
crack_map = gr.Image(label="πΊοΈ Crack Locations Map", interactive=False)
|
40 |
-
crack_list = gr.Dataframe(headers=["Type", "Confidence"], label="Detected Cracks (Last 100+)")
|
41 |
-
|
42 |
-
with gr.Row():
|
43 |
-
pause = gr.Button("βΈ Pause")
|
44 |
-
resume = gr.Button("βΆοΈ Resume")
|
45 |
-
interval_slider = gr.Slider(minimum=0.1, maximum=5.0, value=0.5, step=0.1, label="Frame Interval (seconds)")
|
46 |
-
|
47 |
-
def run_analysis(interval):
|
48 |
-
logs = []
|
49 |
-
crack_data = []
|
50 |
-
|
51 |
-
for frame in stream_video(video_path, interval):
|
52 |
-
processed_frame, crack_count, cracks = process_frame(frame)
|
53 |
-
logs.append(f"Frame processed: {crack_count} cracks detected.")
|
54 |
-
crack_data += cracks[-100:]
|
55 |
-
|
56 |
-
yield {
|
57 |
-
live_feed: processed_frame,
|
58 |
-
crack_metrics: {"Total Cracks": crack_count},
|
59 |
-
live_logs: "\n".join(logs[-10:]),
|
60 |
-
crack_list: crack_data
|
61 |
-
}
|
62 |
-
|
63 |
-
demo.load(run_analysis, inputs=[interval_slider], outputs=[
|
64 |
-
live_feed, crack_metrics, live_logs, crack_list
|
65 |
-
])
|
66 |
|
67 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from utils.frame_extractor import extract_frames
|
3 |
+
from utils.image_utils import save_frame
|
4 |
+
from services import under_construction, operations_maintenance, road_safety, plantation
|
5 |
+
import os
|
6 |
+
|
7 |
+
def process_video(video, category):
|
8 |
+
video_path = video.name
|
9 |
+
frames = extract_frames(video_path)
|
10 |
+
results = []
|
11 |
+
os.makedirs('outputs', exist_ok=True)
|
12 |
+
|
13 |
+
for idx, frame in enumerate(frames[:5]): # Limiting to 5 frames for demonstration
|
14 |
+
if category == "Under Construction":
|
15 |
+
detection = under_construction.detect_under_construction(frame)
|
16 |
+
elif category == "Operations and Maintenance":
|
17 |
+
detection = operations_maintenance.detect_operations_maintenance(frame)
|
18 |
+
elif category == "Road Safety":
|
19 |
+
detection = road_safety.detect_road_safety(frame)
|
20 |
+
elif category == "Plantation":
|
21 |
+
detection = plantation.detect_plantation(frame)
|
22 |
+
else:
|
23 |
+
detection = None
|
24 |
+
|
25 |
+
output_path = f"outputs/frame_{idx}.jpg"
|
26 |
+
save_frame(frame, output_path)
|
27 |
+
results.append(output_path)
|
28 |
+
|
29 |
+
return results
|
30 |
+
|
31 |
+
with gr.Blocks() as demo:
|
32 |
+
gr.Markdown("# π§ Drone Surveillance Analysis")
|
33 |
+
video_input = gr.Video(label="Upload Drone Footage")
|
34 |
+
category = gr.Dropdown(choices=["Under Construction", "Operations and Maintenance", "Road Safety", "Plantation"], label="Select Category")
|
35 |
+
output_gallery = gr.Gallery(label="Detected Frames").style(grid=[2], height="auto")
|
36 |
+
analyze_button = gr.Button("Analyze")
|
37 |
+
|
38 |
+
analyze_button.click(fn=process_video, inputs=[video_input, category], outputs=output_gallery)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
demo.launch()
|