tree_height2 / app.py
nagasurendra's picture
Create app.py
99b5388 verified
raw
history blame
1.02 kB
import gradio as gr
from core_pipeline import extract_frames, detect_trees, plot_detections
import tempfile
import numpy as np
import cv2
def process_video(video):
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as tmp:
tmp.write(video.read())
video_path = tmp.name
frames = extract_frames(video_path)
results = []
for i, frame in enumerate(frames):
detected, bboxes, confs, labels = detect_trees(frame)
annotated = plot_detections(detected, bboxes)
results.append(annotated)
# Stack a preview grid
preview = np.hstack(results[:3]) if results else None
return preview
gr.Interface(
fn=process_video,
inputs=gr.Video(label="Upload Drone Video"),
outputs=gr.Image(label="Tree Detections (Sample Frames)"),
title="🌳 Tree Height Detection from Drone Video",
description="Upload top-down drone video to detect trees and visualize sample frames. Height estimation is possible if SfM data is provided."
).launch()