Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,8 @@ from transformers import Owlv2Processor, Owlv2ForObjectDetection
|
|
| 6 |
import numpy as np
|
| 7 |
import os
|
| 8 |
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
processor = Owlv2Processor.from_pretrained("google/owlv2-base-patch16")
|
| 12 |
model = Owlv2ForObjectDetection.from_pretrained("google/owlv2-base-patch16").to(device)
|
|
@@ -57,7 +58,6 @@ def process_video(video_path, target, progress=gr.Progress()):
|
|
| 57 |
|
| 58 |
frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
| 59 |
original_fps = int(cap.get(cv2.CAP_PROP_FPS))
|
| 60 |
-
original_duration = frame_count / original_fps
|
| 61 |
output_fps = 5
|
| 62 |
|
| 63 |
output_path = "output_video.mp4"
|
|
@@ -113,13 +113,8 @@ def gradio_app():
|
|
| 113 |
use_sample_button = gr.Button("Use Sample Video")
|
| 114 |
progress_bar = gr.Progress()
|
| 115 |
|
| 116 |
-
video_path = gr.State(None)
|
| 117 |
def process_and_update(video, target):
|
| 118 |
output_video_path, error = process_video(video, target, progress_bar)
|
| 119 |
-
if error:
|
| 120 |
-
error_output.visible = True
|
| 121 |
-
else:
|
| 122 |
-
error_output.visible = False
|
| 123 |
return output_video_path, error
|
| 124 |
|
| 125 |
video_input.upload(process_and_update,
|
|
@@ -128,7 +123,8 @@ def gradio_app():
|
|
| 128 |
|
| 129 |
def use_sample_video():
|
| 130 |
sample_video_path = "Drone Video of African Wildlife Wild Botswan.mp4"
|
| 131 |
-
|
|
|
|
| 132 |
|
| 133 |
use_sample_button.click(use_sample_video,
|
| 134 |
inputs=None,
|
|
|
|
| 6 |
import numpy as np
|
| 7 |
import os
|
| 8 |
|
| 9 |
+
# Check if CUDA is available, otherwise use CPU
|
| 10 |
+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
| 11 |
|
| 12 |
processor = Owlv2Processor.from_pretrained("google/owlv2-base-patch16")
|
| 13 |
model = Owlv2ForObjectDetection.from_pretrained("google/owlv2-base-patch16").to(device)
|
|
|
|
| 58 |
|
| 59 |
frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
| 60 |
original_fps = int(cap.get(cv2.CAP_PROP_FPS))
|
|
|
|
| 61 |
output_fps = 5
|
| 62 |
|
| 63 |
output_path = "output_video.mp4"
|
|
|
|
| 113 |
use_sample_button = gr.Button("Use Sample Video")
|
| 114 |
progress_bar = gr.Progress()
|
| 115 |
|
|
|
|
| 116 |
def process_and_update(video, target):
|
| 117 |
output_video_path, error = process_video(video, target, progress_bar)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
return output_video_path, error
|
| 119 |
|
| 120 |
video_input.upload(process_and_update,
|
|
|
|
| 123 |
|
| 124 |
def use_sample_video():
|
| 125 |
sample_video_path = "Drone Video of African Wildlife Wild Botswan.mp4"
|
| 126 |
+
output_video_path, error = process_and_update(sample_video_path, "animal")
|
| 127 |
+
return output_video_path, error
|
| 128 |
|
| 129 |
use_sample_button.click(use_sample_video,
|
| 130 |
inputs=None,
|