HuggingFaceM4/ChartQA
Viewer • Updated • 32.7k • 13.5k • 65
Fine-tuned version of Qwen2-VL-2B-Instruct on the ChartQA dataset for visual question answering on charts.
from transformers import AutoProcessor, Qwen2VLForConditionalGeneration
from PIL import Image
import torch
model_id = "Devildarker6789/qwen2vl-chartqa"
processor = AutoProcessor.from_pretrained(model_id, min_pixels=256*28*28, max_pixels=512*28*28)
model = Qwen2VLForConditionalGeneration.from_pretrained(
model_id,
torch_dtype=torch.float16,
device_map="auto"
)
model.eval()
image = Image.open("your_chart.png").convert("RGB")
question = "What is the highest value in this chart?"
messages = [{"role": "user", "content": [
{"type": "image", "image": image},
{"type": "text", "text": question}
]}]
text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = processor(text=[text], images=[image], return_tensors="pt").to(model.device)
with torch.no_grad():
out = model.generate(**inputs, max_new_tokens=64, do_sample=False)
print(processor.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
Then click **Save** — and your HF link is: