nagasurendra commited on
Commit
7ece5c2
·
verified ·
1 Parent(s): 5013184

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -11
app.py CHANGED
@@ -1,29 +1,27 @@
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."
 
1
  import gradio as gr
2
  from core_pipeline import extract_frames, detect_trees, plot_detections
 
3
  import numpy as np
 
4
 
5
+ def process_video(video_path):
6
+ if not video_path:
7
+ return None
 
8
 
9
  frames = extract_frames(video_path)
10
  results = []
11
 
12
+ for i, frame in enumerate(frames[:3]): # limit to 3 sample frames for preview
13
  detected, bboxes, confs, labels = detect_trees(frame)
14
  annotated = plot_detections(detected, bboxes)
15
  results.append(annotated)
16
 
17
+ if results:
18
+ preview = np.hstack(results)
19
+ return preview
20
+ return None
21
 
22
  gr.Interface(
23
  fn=process_video,
24
+ inputs=gr.Video(label="Upload Drone Video", type="filepath"),
25
  outputs=gr.Image(label="Tree Detections (Sample Frames)"),
26
  title="🌳 Tree Height Detection from Drone Video",
27
  description="Upload top-down drone video to detect trees and visualize sample frames. Height estimation is possible if SfM data is provided."