Spaces:
Runtime error
Runtime error
autism_plus_edynamix_demo_14
Browse files- src/minicpm/response.py +19 -1
src/minicpm/response.py
CHANGED
@@ -2,7 +2,8 @@
|
|
2 |
import sys
|
3 |
import gradio as gr
|
4 |
import spaces
|
5 |
-
|
|
|
6 |
# Local imports
|
7 |
from src.config import (
|
8 |
device,
|
@@ -18,7 +19,24 @@ from src.exception import CustomExceptionHandling
|
|
18 |
|
19 |
# Model, tokenizer and processor
|
20 |
model, tokenizer, processor = load_model_tokenizer_and_processor(model_name, device)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
@spaces.GPU(duration=120)
|
24 |
def describe_image(
|
|
|
2 |
import sys
|
3 |
import gradio as gr
|
4 |
import spaces
|
5 |
+
from decord import VideoReader, cpu
|
6 |
+
from PIL import Image
|
7 |
# Local imports
|
8 |
from src.config import (
|
9 |
device,
|
|
|
19 |
|
20 |
# Model, tokenizer and processor
|
21 |
model, tokenizer, processor = load_model_tokenizer_and_processor(model_name, device)
|
22 |
+
MAX_NUM_FRAMES=64
|
23 |
+
|
24 |
+
def encode_video(video_path):
|
25 |
+
MAX_NUM_FRAMES=64
|
26 |
+
def uniform_sample(l, n):
|
27 |
+
gap = len(l) / n
|
28 |
+
idxs = [int(i * gap + gap / 2) for i in range(n)]
|
29 |
+
return [l[i] for i in idxs]
|
30 |
|
31 |
+
vr = VideoReader(video_path, ctx=cpu(0))
|
32 |
+
sample_fps = round(vr.get_avg_fps() / 1) # FPS
|
33 |
+
frame_idx = [i for i in range(0, len(vr), sample_fps)]
|
34 |
+
if len(frame_idx) > MAX_NUM_FRAMES:
|
35 |
+
frame_idx = uniform_sample(frame_idx, MAX_NUM_FRAMES)
|
36 |
+
frames = vr.get_batch(frame_idx).asnumpy()
|
37 |
+
frames = [Image.fromarray(v.astype('uint8')) for v in frames]
|
38 |
+
print('num frames:', len(frames))
|
39 |
+
return frames
|
40 |
|
41 |
@spaces.GPU(duration=120)
|
42 |
def describe_image(
|