akhaliq HF Staff commited on
Commit
8eb2595
·
verified ·
1 Parent(s): 77c5fd0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -1
app.py CHANGED
@@ -7,6 +7,7 @@ from scipy.spatial import cKDTree
7
  import numpy as np
8
  import math
9
  import time
 
10
 
11
  # Model initialization
12
  model = None
@@ -26,7 +27,7 @@ def load_model():
26
  attn_implementation='sdpa',
27
  torch_dtype=torch.bfloat16
28
  )
29
- model = model.eval().cuda()
30
  tokenizer = AutoTokenizer.from_pretrained(
31
  'openbmb/MiniCPM-V-4_5',
32
  trust_remote_code=True
@@ -84,6 +85,7 @@ def encode_video(video_path, choose_fps=3, force_packing=None):
84
 
85
  return frames, frame_ts_id_group, video_duration, len(frame_idx), packing_nums
86
 
 
87
  def process_video_and_question(video, question, fps, force_packing, history):
88
  if video is None:
89
  gr.Warning("Please upload a video first.")
@@ -96,6 +98,7 @@ def process_video_and_question(video, question, fps, force_packing, history):
96
  try:
97
  # Load model if not already loaded
98
  model, tokenizer = load_model()
 
99
 
100
  # Encode video
101
  gr.Info(f"Processing video with {fps} FPS...")
 
7
  import numpy as np
8
  import math
9
  import time
10
+ import spaces
11
 
12
  # Model initialization
13
  model = None
 
27
  attn_implementation='sdpa',
28
  torch_dtype=torch.bfloat16
29
  )
30
+ model = model.eval()
31
  tokenizer = AutoTokenizer.from_pretrained(
32
  'openbmb/MiniCPM-V-4_5',
33
  trust_remote_code=True
 
85
 
86
  return frames, frame_ts_id_group, video_duration, len(frame_idx), packing_nums
87
 
88
+ @spaces.GPU(duration=60)
89
  def process_video_and_question(video, question, fps, force_packing, history):
90
  if video is None:
91
  gr.Warning("Please upload a video first.")
 
98
  try:
99
  # Load model if not already loaded
100
  model, tokenizer = load_model()
101
+ model = model.cuda()
102
 
103
  # Encode video
104
  gr.Info(f"Processing video with {fps} FPS...")