Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from core_pipeline import extract_frames, detect_trees, plot_detections
|
3 |
+
import tempfile
|
4 |
+
import numpy as np
|
5 |
+
import cv2
|
6 |
+
|
7 |
+
def process_video(video):
|
8 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as tmp:
|
9 |
+
tmp.write(video.read())
|
10 |
+
video_path = tmp.name
|
11 |
+
|
12 |
+
frames = extract_frames(video_path)
|
13 |
+
results = []
|
14 |
+
|
15 |
+
for i, frame in enumerate(frames):
|
16 |
+
detected, bboxes, confs, labels = detect_trees(frame)
|
17 |
+
annotated = plot_detections(detected, bboxes)
|
18 |
+
results.append(annotated)
|
19 |
+
|
20 |
+
# Stack a preview grid
|
21 |
+
preview = np.hstack(results[:3]) if results else None
|
22 |
+
return preview
|
23 |
+
|
24 |
+
gr.Interface(
|
25 |
+
fn=process_video,
|
26 |
+
inputs=gr.Video(label="Upload Drone Video"),
|
27 |
+
outputs=gr.Image(label="Tree Detections (Sample Frames)"),
|
28 |
+
title="🌳 Tree Height Detection from Drone Video",
|
29 |
+
description="Upload top-down drone video to detect trees and visualize sample frames. Height estimation is possible if SfM data is provided."
|
30 |
+
).launch()
|