Spaces:
Runtime error
Runtime error
File size: 1,454 Bytes
021fd45 6d16e6e 021fd45 6d16e6e 021fd45 5642ff6 deb3cb9 021fd45 deb3cb9 6d16e6e 021fd45 6d16e6e 021fd45 6d16e6e 021fd45 6d16e6e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
from transformers import AutoProcessor, AutoModelForCausalLM
import torch
import gradio as gr
# Ensure you use the latest version of transformers!
# For example, in your requirements.txt, you might include:
# transformers>=4.31.0
# Load the processor and model while trusting remote code.
processor = AutoProcessor.from_pretrained(
"lmms-lab/LLaVA-Video-7B-Qwen2",
trust_remote_code=True
)
model = AutoModelForCausalLM.from_pretrained(
"lmms-lab/LLaVA-Video-7B-Qwen2",
trust_remote_code=True
)
device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device)
def analyze_video(video_path):
prompt = "Analyze this video of a concert and determine the moment when the crowd is most engaged."
# The processor is expected to handle both text and video input.
inputs = processor(text=prompt, video=video_path, return_tensors="pt")
inputs = {k: v.to(device) for k, v in inputs.items()}
outputs = model.generate(**inputs, max_new_tokens=100)
answer = processor.decode(outputs[0], skip_special_tokens=True)
return answer
iface = gr.Interface(
fn=analyze_video,
inputs=gr.Video(label="Upload Concert/Event Video", type="filepath"),
outputs=gr.Textbox(label="Engagement Analysis"),
title="Crowd Engagement Analyzer",
description="Upload a video of a concert or event and the model will analyze the moment when the crowd is most engaged."
)
if __name__ == "__main__":
iface.launch()
|