Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -23,17 +23,16 @@ def sample_video_frames(video_path, num_frames=NUM_FRAMES):
|
|
23 |
# 推理函数:加载模型、采样视频帧、推理
|
24 |
@spaces.GPU
|
25 |
def analyze_video(video_file):
|
26 |
-
#
|
27 |
-
frames = sample_video_frames(video_file
|
28 |
|
29 |
-
#
|
30 |
system_prompt = (
|
31 |
"You are a helpful AI assistant that analyzes AR effects in videos. "
|
32 |
"Evaluate the realism and placement of virtual objects in the provided video frames."
|
33 |
)
|
34 |
user_prompt = "Based on the frames, describe how well the AR objects blend into the real environment."
|
35 |
|
36 |
-
# 构造输入对话历史(含图像)
|
37 |
history = [
|
38 |
{
|
39 |
"role": "system",
|
@@ -45,7 +44,6 @@ def analyze_video(video_file):
|
|
45 |
}
|
46 |
]
|
47 |
|
48 |
-
# 调用 pipeline 推理
|
49 |
pipe = pipeline(
|
50 |
"image-text-to-text",
|
51 |
model=model_id,
|
@@ -53,9 +51,11 @@ def analyze_video(video_file):
|
|
53 |
torch_dtype=torch.bfloat16,
|
54 |
model_kwargs={"device_map": "auto"}
|
55 |
)
|
|
|
56 |
result = pipe(text=history, max_new_tokens=512)
|
57 |
return result[0]["generated_text"][-1]["content"]
|
58 |
|
|
|
59 |
# Gradio 界面
|
60 |
gr.Interface(
|
61 |
fn=analyze_video,
|
|
|
23 |
# 推理函数:加载模型、采样视频帧、推理
|
24 |
@spaces.GPU
|
25 |
def analyze_video(video_file):
|
26 |
+
# video_file 是路径字符串
|
27 |
+
frames = sample_video_frames(video_file)
|
28 |
|
29 |
+
# 构造 prompt
|
30 |
system_prompt = (
|
31 |
"You are a helpful AI assistant that analyzes AR effects in videos. "
|
32 |
"Evaluate the realism and placement of virtual objects in the provided video frames."
|
33 |
)
|
34 |
user_prompt = "Based on the frames, describe how well the AR objects blend into the real environment."
|
35 |
|
|
|
36 |
history = [
|
37 |
{
|
38 |
"role": "system",
|
|
|
44 |
}
|
45 |
]
|
46 |
|
|
|
47 |
pipe = pipeline(
|
48 |
"image-text-to-text",
|
49 |
model=model_id,
|
|
|
51 |
torch_dtype=torch.bfloat16,
|
52 |
model_kwargs={"device_map": "auto"}
|
53 |
)
|
54 |
+
|
55 |
result = pipe(text=history, max_new_tokens=512)
|
56 |
return result[0]["generated_text"][-1]["content"]
|
57 |
|
58 |
+
|
59 |
# Gradio 界面
|
60 |
gr.Interface(
|
61 |
fn=analyze_video,
|