SathvikGanta commited on
Commit
06a27bd
Β·
verified Β·
1 Parent(s): bbe92da

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -64
app.py CHANGED
@@ -1,67 +1,40 @@
1
  import gradio as gr
2
- import cv2
3
- import numpy as np
4
- from video_utils import stream_video
5
- from usecases.crack_detector import detect_cracks
6
- # from usecases.pothole_detector import detect_potholes # Enable for potholes
7
-
8
- video_path = "assets/Drone_Video.mp4"
9
-
10
- def process_frame(frame):
11
- crack_frame, crack_results = detect_cracks(frame)
12
- # pothole_frame, pothole_results = detect_potholes(frame)
13
-
14
- # Combine annotated outputs (can be composited visually if needed)
15
- combined = crack_frame # For now just cracks
16
-
17
- cracks = []
18
- for box in crack_results.boxes:
19
- cls = crack_results.names[int(box.cls[0])]
20
- conf = round(float(box.conf[0]), 2)
21
- cracks.append([cls, conf])
22
-
23
- return combined, len(crack_results.boxes), cracks
24
-
25
- with gr.Blocks(title="Drone Road Inspection Dashboard") as demo:
26
- gr.Markdown("## 🚁 Drone Road Inspection Dashboard")
27
- gr.Markdown("**Status:** 🟒 Running")
28
-
29
- with gr.Row():
30
- live_feed = gr.Image(label="πŸ“Ί Live Drone Feed", interactive=False)
31
- crack_metrics = gr.Label(label="πŸ“Š Crack Metrics")
32
-
33
- with gr.Row():
34
- live_logs = gr.Textbox(label="🧾 Live Logs", interactive=False, lines=6)
35
- crack_trend = gr.Plot(label="πŸ“ˆ Crack Trend")
36
- crack_severity = gr.Label(label="🚨 Crack Severity")
37
-
38
- with gr.Row():
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()