from PIL import Imageimport torchfrom transformers import AutoModelForImageTextToText, AutoProcessor repo = "LoNebula/okinawa-sign-vlm"processor = AutoProcessor.from_pretrained(repo)model = AutoModelForImageTextToText.from_pretrained(repo)image = Image.open("sign.png").convert("RGB") messages = [{ "role": "user", "content": [ {"type": "image"}, {"type": "text", "text": ( "Read the Japanese vocabulary shown in this Okinawa-style learning sign. " "Give its Shuri Okinawan dictionary form. Reply with only the dictionary form." )}, ],}]prompt = processor.apply_chat_template(messages, add_generation_prompt=True)inputs = processor(text=prompt, images=[image], return_tensors="pt")device = next(model.parameters()).deviceinputs = {key: value.to(device) if hasattr(value, "to") else value for key, value in inputs.items()}with torch.inference_mode(): generated = model.generate(**inputs, max_new_tokens=48, do_sample=False)prompt_length = inputs["input_ids"].shape[1]print(processor.batch_decode(generated[:, prompt_length:], skip_special_tokens=True)[0])