1from transformers import AutoProcessor, AutoModelForImageTextToText
2from PIL import Image
3import torch
4
5model_id = "Surpem/Supertron-VL-4B"
6
7processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
8model = AutoModelForImageTextToText.from_pretrained(
9 model_id,
10 torch_dtype=torch.bfloat16,
11 device_map="auto",
12 trust_remote_code=True,
13)
14
15image = Image.open("chart.png").convert("RGB")
16question = "What is the highest value shown in the chart?"
17messages = [
18 {
19 "role": "user",
20 "content": [
21 {"type": "image", "image": image},
22 {
23 "type": "text",
24 "text": (
25 "Read the chart image and answer the question concisely. "
26 "Return only the final answer, without chain-of-thought.\n"
27 f"Question: {question}"
28 ),
29 },
30 ],
31 }
32]
33
34text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
35inputs = processor(text=[text], images=[image], padding=True, return_tensors="pt").to(model.device)
36outputs = model.generate(**inputs, max_new_tokens=48, do_sample=False)
37generated = outputs[:, inputs["input_ids"].shape[1]:]
38print(processor.batch_decode(generated, skip_special_tokens=True)[0].strip())
Supertron-VL-4B is specialized for chart question answering. It may make mistakes on crowded charts, ambiguous labels, color-only questions, arithmetic-heavy questions, or charts with very small text.