baohuynhbk14 commited on
Commit
706937a
·
verified ·
1 Parent(s): bf64d49

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -8
app.py CHANGED
@@ -144,15 +144,9 @@ def navigate_pdf_page(direction: str, state: Dict[str, Any]):
144
  return image_preview, state, page_info_html
145
 
146
  def downsample_video(video_path):
147
- """
148
- Downsamples the video to evenly spaced frames.
149
- Each frame is returned as a PIL image along with its timestamp.
150
- """
151
  vidcap = cv2.VideoCapture(video_path)
152
  total_frames = int(vidcap.get(cv2.CAP_PROP_FRAME_COUNT))
153
- fps = vidcap.get(cv2.CAP_PROP_FPS)
154
  frames = []
155
- # Use a maximum of 10 frames to avoid excessive memory usage
156
  frame_indices = np.linspace(0, total_frames - 1, min(total_frames, 10), dtype=int)
157
  for i in frame_indices:
158
  vidcap.set(cv2.CAP_PROP_POS_FRAMES, i)
@@ -160,8 +154,7 @@ def downsample_video(video_path):
160
  if success:
161
  image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
162
  pil_image = Image.fromarray(image)
163
- timestamp = round(i / fps, 2)
164
- frames.append((pil_image, timestamp))
165
  vidcap.release()
166
  return frames
167
 
@@ -270,6 +263,7 @@ def generate_video(model_name: str, text: str, video_path: str,
270
  time.sleep(0.01)
271
  yield buffer, buffer
272
 
 
273
  @spaces.GPU
274
  def generate_pdf(model_name: str, text: str, state: Dict[str, Any],
275
  max_new_tokens: int = 2048,
 
144
  return image_preview, state, page_info_html
145
 
146
  def downsample_video(video_path):
 
 
 
 
147
  vidcap = cv2.VideoCapture(video_path)
148
  total_frames = int(vidcap.get(cv2.CAP_PROP_FRAME_COUNT))
 
149
  frames = []
 
150
  frame_indices = np.linspace(0, total_frames - 1, min(total_frames, 10), dtype=int)
151
  for i in frame_indices:
152
  vidcap.set(cv2.CAP_PROP_POS_FRAMES, i)
 
154
  if success:
155
  image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
156
  pil_image = Image.fromarray(image)
157
+ frames.append(pil_image)
 
158
  vidcap.release()
159
  return frames
160
 
 
263
  time.sleep(0.01)
264
  yield buffer, buffer
265
 
266
+
267
  @spaces.GPU
268
  def generate_pdf(model_name: str, text: str, state: Dict[str, Any],
269
  max_new_tokens: int = 2048,