Update app.py
Browse files
app.py
CHANGED
|
@@ -1,51 +1,25 @@
|
|
| 1 |
-
'''
|
| 2 |
import gradio as gr
|
| 3 |
-
from utils import extract_frames
|
| 4 |
from model import predict_defect
|
| 5 |
-
|
| 6 |
-
def analyze_video(video):
|
| 7 |
-
frames = extract_frames(video)
|
| 8 |
-
results = [predict_defect(frame) for frame in frames]
|
| 9 |
-
return results
|
| 10 |
-
|
| 11 |
-
demo = gr.Interface(
|
| 12 |
-
fn=analyze_video,
|
| 13 |
-
inputs=gr.Video(label="Upload Drone Video"),
|
| 14 |
-
outputs=gr.Gallery(label="Detected Road Defects")
|
| 15 |
-
,
|
| 16 |
-
title="Drone-based Road Defect Detection",
|
| 17 |
-
description="Upload drone footage to identify and highlight road surface defects."
|
| 18 |
-
)
|
| 19 |
-
|
| 20 |
-
if __name__ == "__main__":
|
| 21 |
-
demo.launch()
|
| 22 |
-
'''
|
| 23 |
-
|
| 24 |
-
import gradio as gr
|
| 25 |
-
import os
|
| 26 |
from utils import extract_frames
|
| 27 |
-
|
| 28 |
|
| 29 |
-
# === 1. Load videos from the Data folder ===
|
| 30 |
DATA_DIR = "Data"
|
| 31 |
|
| 32 |
def get_video_choices():
|
| 33 |
return [os.path.join(DATA_DIR, f) for f in os.listdir(DATA_DIR) if f.endswith(".mp4")]
|
| 34 |
|
| 35 |
-
# === 2. Analyze selected video ===
|
| 36 |
def analyze_selected_video(video_path):
|
| 37 |
frames = extract_frames(video_path)
|
| 38 |
results = [predict_defect(frame) for frame in frames]
|
| 39 |
return results
|
| 40 |
|
| 41 |
-
# === 3. Gradio interface ===
|
| 42 |
demo = gr.Interface(
|
| 43 |
fn=analyze_selected_video,
|
| 44 |
-
inputs=gr.Dropdown(choices=get_video_choices(), label="Select Drone Video"),
|
| 45 |
outputs=gr.Gallery(label="Detected Road Defects"),
|
| 46 |
title="Drone-based Road Defect Detection",
|
| 47 |
-
description="
|
| 48 |
)
|
| 49 |
|
| 50 |
if __name__ == "__main__":
|
| 51 |
-
demo.launch()
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from model import predict_defect
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from utils import extract_frames
|
| 4 |
+
import os
|
| 5 |
|
|
|
|
| 6 |
DATA_DIR = "Data"
|
| 7 |
|
| 8 |
def get_video_choices():
|
| 9 |
return [os.path.join(DATA_DIR, f) for f in os.listdir(DATA_DIR) if f.endswith(".mp4")]
|
| 10 |
|
|
|
|
| 11 |
def analyze_selected_video(video_path):
|
| 12 |
frames = extract_frames(video_path)
|
| 13 |
results = [predict_defect(frame) for frame in frames]
|
| 14 |
return results
|
| 15 |
|
|
|
|
| 16 |
demo = gr.Interface(
|
| 17 |
fn=analyze_selected_video,
|
| 18 |
+
inputs=gr.Dropdown(choices=lambda: get_video_choices(), label="Select Drone Video"),
|
| 19 |
outputs=gr.Gallery(label="Detected Road Defects"),
|
| 20 |
title="Drone-based Road Defect Detection",
|
| 21 |
+
description="Highlight road defects (cracks, potholes, misalignments) in red using video frames."
|
| 22 |
)
|
| 23 |
|
| 24 |
if __name__ == "__main__":
|
| 25 |
+
demo.launch()
|