Views
No views yet
Qwen/Qwen2-VL-7B-Instruct| File | Description |
|---|---|
adapter_model.safetensors | LoRA adapter weights |
adapter_config.json | PEFT adapter configuration |
tokenizer.json | Tokenizer vocabulary |
tokenizer_config.json | Tokenizer configuration |
1from transformers import AutoProcessor, Qwen2VLForConditionalGeneration
2from peft import PeftModel
3from PIL import Image
4from huggingface_hub import snapshot_download
5
6# Download adapter
7adapter_dir = snapshot_download(repo_id='devanshty/Babel')
8
9# Load base model
10base_model = Qwen2VLForConditionalGeneration.from_pretrained(
11 "Qwen/Qwen2-VL-7B-Instruct",
12 torch_dtype="auto",
13 device_map="auto"
14)
15processor = AutoProcessor.from_pretrained(adapter_dir)
16
17# Load LoRA adapter
18model = PeftModel.from_pretrained(base_model, adapter_dir)
19model.eval()
20
21# OCR + Translate
22image = Image.open("document.jpg")
23messages = [
24 {
25 "role": "user",
26 "content": [
27 {"type": "image", "image": image},
28 {"type": "text", "text": "Extract all text from this image and translate it to English."}
29 ]
30 }
31]
32text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
33inputs = processor(text=[text], images=[image], return_tensors="pt").to(model.device)
34output = model.generate(**inputs, max_new_tokens=1024)
35print(processor.decode(output[0], skip_special_tokens=True))1from huggingface_hub import hf_hub_download
2adapter = hf_hub_download(repo_id='devanshty/Babel', filename='adapter_model.safetensors')