Tonic commited on
Commit
b841cef
•
1 Parent(s): afafb21

add file management

Browse files
Files changed (1) hide show
  1. app.py +18 -5
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,21 @@ 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
- response = process_video(video_file, question)
 
 
 
 
 
 
 
 
 
 
 
 
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 +123,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
+ import shutil
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
+ # Create a temporary directory to store the video
95
+ with tempfile.TemporaryDirectory() as temp_dir:
96
+ temp_video_path = os.path.join(temp_dir, "temp_video.mp4")
97
+
98
+ # Copy the video file to the temporary directory
99
+ shutil.copy2(video_file, temp_video_path)
100
+
101
+ try:
102
+ response = process_video(temp_video_path, question)
103
+ except Exception as e:
104
+ return f"An error occurred: {str(e)}"
105
+
106
  return response
107
 
 
108
  with gr.Blocks() as demo:
109
  gr.Markdown("# LLaVA-Video-7B-Qwen2 Demo")
110
  gr.Markdown("Upload a video and ask a question about it.")
 
123
  )
124
 
125
  if __name__ == "__main__":
126
+ demo.launch(show_error=True)