Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,25 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
-
from transformers import AutoProcessor,
|
4 |
|
5 |
# Load the processor and model with remote code enabled.
|
6 |
processor = AutoProcessor.from_pretrained(
|
7 |
"lmms-lab/LLaVA-Video-7B-Qwen2",
|
8 |
trust_remote_code=True
|
9 |
)
|
10 |
-
model =
|
11 |
"lmms-lab/LLaVA-Video-7B-Qwen2",
|
12 |
trust_remote_code=True
|
13 |
)
|
14 |
|
15 |
-
# Use GPU if available.
|
16 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
17 |
model.to(device)
|
18 |
|
19 |
def analyze_video(video_path):
|
20 |
prompt = "Analyze this video of a concert and determine the moment when the crowd is most engaged."
|
21 |
-
# Process text and video.
|
22 |
inputs = processor(text=prompt, video=video_path, return_tensors="pt")
|
23 |
inputs = {k: v.to(device) for k, v in inputs.items()}
|
24 |
-
|
25 |
-
# Generate a response (this assumes the remote code has added a generate method).
|
26 |
outputs = model.generate(**inputs, max_new_tokens=100)
|
27 |
-
|
28 |
-
# Decode the output tokens.
|
29 |
answer = processor.decode(outputs[0], skip_special_tokens=True)
|
30 |
return answer
|
31 |
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
+
from transformers import AutoProcessor, AutoModelForCausalLM
|
4 |
|
5 |
# Load the processor and model with remote code enabled.
|
6 |
processor = AutoProcessor.from_pretrained(
|
7 |
"lmms-lab/LLaVA-Video-7B-Qwen2",
|
8 |
trust_remote_code=True
|
9 |
)
|
10 |
+
model = AutoModelForCausalLM.from_pretrained(
|
11 |
"lmms-lab/LLaVA-Video-7B-Qwen2",
|
12 |
trust_remote_code=True
|
13 |
)
|
14 |
|
|
|
15 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
16 |
model.to(device)
|
17 |
|
18 |
def analyze_video(video_path):
|
19 |
prompt = "Analyze this video of a concert and determine the moment when the crowd is most engaged."
|
|
|
20 |
inputs = processor(text=prompt, video=video_path, return_tensors="pt")
|
21 |
inputs = {k: v.to(device) for k, v in inputs.items()}
|
|
|
|
|
22 |
outputs = model.generate(**inputs, max_new_tokens=100)
|
|
|
|
|
23 |
answer = processor.decode(outputs[0], skip_special_tokens=True)
|
24 |
return answer
|
25 |
|