Spaces:
Running
on
Zero
Running
on
Zero
add file management
Browse files
app.py
CHANGED
@@ -21,8 +21,10 @@ import copy
|
|
21 |
import warnings
|
22 |
from decord import VideoReader, cpu
|
23 |
import numpy as np
|
|
|
|
|
24 |
|
25 |
-
warnings.filterwarnings("ignore")
|
26 |
|
27 |
def load_video(video_path, max_frames_num, fps=1, force_sample=False):
|
28 |
if max_frames_num == 0:
|
@@ -88,10 +90,19 @@ def process_video(video_path, question):
|
|
88 |
def gradio_interface(video_file, question):
|
89 |
if video_file is None:
|
90 |
return "Please upload a video file."
|
91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
return response
|
93 |
|
94 |
-
# Create Gradio app
|
95 |
with gr.Blocks() as demo:
|
96 |
gr.Markdown("# LLaVA-Video-7B-Qwen2 Demo")
|
97 |
gr.Markdown("Upload a video and ask a question about it.")
|
@@ -110,4 +121,4 @@ with gr.Blocks() as demo:
|
|
110 |
)
|
111 |
|
112 |
if __name__ == "__main__":
|
113 |
-
demo.launch()
|
|
|
21 |
import warnings
|
22 |
from decord import VideoReader, cpu
|
23 |
import numpy as np
|
24 |
+
import tempfile
|
25 |
+
import os
|
26 |
|
27 |
+
#warnings.filterwarnings("ignore")
|
28 |
|
29 |
def load_video(video_path, max_frames_num, fps=1, force_sample=False):
|
30 |
if max_frames_num == 0:
|
|
|
90 |
def gradio_interface(video_file, question):
|
91 |
if video_file is None:
|
92 |
return "Please upload a video file."
|
93 |
+
|
94 |
+
# Save the uploaded video to a temporary file
|
95 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_video:
|
96 |
+
temp_video.write(video_file.read())
|
97 |
+
temp_video_path = temp_video.name
|
98 |
+
|
99 |
+
try:
|
100 |
+
response = process_video(temp_video_path, question)
|
101 |
+
finally:
|
102 |
+
os.unlink(temp_video_path)
|
103 |
+
|
104 |
return response
|
105 |
|
|
|
106 |
with gr.Blocks() as demo:
|
107 |
gr.Markdown("# LLaVA-Video-7B-Qwen2 Demo")
|
108 |
gr.Markdown("Upload a video and ask a question about it.")
|
|
|
121 |
)
|
122 |
|
123 |
if __name__ == "__main__":
|
124 |
+
demo.launch(show_error=True)
|