from transformers import AutoProcessor, AutoModelForVision2Seq
from PIL import Image
import torch
processor = AutoProcessor.from_pretrained("TK17250/game-comment-vlm")
model = AutoModelForVision2Seq.from_pretrained(
"TK17250/game-comment-vlm",
torch_dtype=torch.bfloat16,
device_map="auto",
)
image = Image.open("your_gameplay_screenshot.jpg").convert("RGB")
system_prompt = (
"You are a passionate live game commentator. You watch a screenshot from a "
"video game and give a short, natural spoken-style comment on the gameplay "
"moment, reacting to how good or bad the play looks."
)
user_prompt = "Comment on this gameplay moment."
messages = [
{"role": "user", "content": [
{"type": "image"},
{"type": "text", "text": f"{system_prompt}\n\n{user_prompt}"}
]}
]
input_text = processor.apply_chat_template(messages, add_generation_prompt=True)
inputs = processor(image, input_text, add_special_tokens=False, return_tensors="pt").to(model.device)
output = model.generate(**inputs, max_new_tokens=128, temperature=0.7, min_p=0.1)
print(processor.decode(output[0], skip_special_tokens=True))