Views
No views yet
1from transformers import Qwen2_5_VLProcessor, Qwen2_5_VLForConditionalGeneration
2from PIL import Image
3
4# Load model and processor
5model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
6 "vrushankkk/qwen-2.5-3b-vl-fine-tuned",
7 torch_dtype="auto",
8 device_map="auto"
9)
10processor = Qwen2_5_VLProcessor.from_pretrained("vrushankkk/qwen-2.5-3b-vl-fine-tuned")
11
12# Prepare your image and prompt
13image = Image.open("your_invoice.jpg")
14prompt = "Extract invoice data and return as JSON"
15
16# Process inputs
17inputs = processor(text=prompt, images=image, return_tensors="pt")
18
19# Generate response
20with torch.no_grad():
21 outputs = model.generate(**inputs, max_new_tokens=512)
22
23response = processor.decode(outputs[0], skip_special_tokens=True)
24print(response)