Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,19 +6,21 @@ import tempfile
|
|
6 |
import imageio
|
7 |
from decord import VideoReader, cpu
|
8 |
from transformers import pipeline
|
|
|
9 |
|
10 |
hf_token = os.environ.get("HUGGINGFACE_TOKEN")
|
11 |
model_id = "google/gemma-3-27b-it"
|
12 |
NUM_FRAMES = 8
|
13 |
|
14 |
# 从视频中采样 N 帧
|
15 |
-
def sample_video_frames(video_path, num_frames=
|
16 |
vr = VideoReader(video_path, ctx=cpu(0))
|
17 |
total_frames = len(vr)
|
18 |
indices = [int(i) for i in torch.linspace(0, total_frames - 1, steps=num_frames)]
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
22 |
|
23 |
# 推理函数:加载模型、采样视频帧、推理
|
24 |
@spaces.GPU
|
|
|
6 |
import imageio
|
7 |
from decord import VideoReader, cpu
|
8 |
from transformers import pipeline
|
9 |
+
from PIL import Image
|
10 |
|
11 |
hf_token = os.environ.get("HUGGINGFACE_TOKEN")
|
12 |
model_id = "google/gemma-3-27b-it"
|
13 |
NUM_FRAMES = 8
|
14 |
|
15 |
# 从视频中采样 N 帧
|
16 |
+
def sample_video_frames(video_path, num_frames=8):
|
17 |
vr = VideoReader(video_path, ctx=cpu(0))
|
18 |
total_frames = len(vr)
|
19 |
indices = [int(i) for i in torch.linspace(0, total_frames - 1, steps=num_frames)]
|
20 |
+
|
21 |
+
# 关键点:强制转换为 PIL.Image
|
22 |
+
frames = [Image.fromarray(vr[i].asnumpy()) for i in indices]
|
23 |
+
return frames
|
24 |
|
25 |
# 推理函数:加载模型、采样视频帧、推理
|
26 |
@spaces.GPU
|