optiviseapp/arabic-doc-extractor-qwen25vl-3b
0
Arabic Document Extractor โ Qwen2.5-VL-3B + QLoRA
๐ญ Purpose: Extract structured data from Arabic PDF work orders, invoices, tables, and documents for factory automation.
Model Details
Training Data
Capabilities
โ Arabic OCR โ Read printed Arabic text from scanned documents โ Structured Extraction โ Extract key-value pairs as JSON from work orders โ Table Extraction โ Convert Arabic financial/data tables to structured JSON โ Markdown Conversion โ Convert Arabic PDFs to formatted Markdown โ Bilingual โ Handles mixed Arabic/English documents
Quick Start
Installation
pip install transformers peft torch qwen-vl-utils PillowInference
from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor
from peft import PeftModel
from PIL import Image
import torch
# Load base + adapter
base = Qwen2_5_VLForConditionalGeneration.from_pretrained(
"Qwen/Qwen2.5-VL-3B-Instruct",
torch_dtype=torch.bfloat16,
device_map="auto",
)
model = PeftModel.from_pretrained(base, "optiviseapp/arabic-doc-extractor-qwen25vl-3b")
processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-3B-Instruct")
# Extract from work order
image = Image.open("work_order.png").convert("RGB")
messages = [{
"role": "user",
"content": [
{"type": "image", "image": image},
{"type": "text", "text": "ุงุณุชุฎุฑุฌ ุฌู
ูุน ุงูุจูุงูุงุช ู
ู ุฃู
ุฑ ุงูุนู
ู ูุฐุง ุจุตูุบุฉ JSON"}
],
}]
text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
from qwen_vl_utils import process_vision_info
image_inputs, _ = process_vision_info(messages)
inputs = processor(text=[text], images=image_inputs, return_tensors="pt").to(model.device)
output = model.generate(**inputs, max_new_tokens=2000)
result = processor.batch_decode(
[o[len(i):] for i, o in zip(inputs.input_ids, output)],
skip_special_tokens=True
)[0]
print(result)Work Order Extraction Prompt (Arabic)
ุงุณุชุฎุฑุฌ ุฌู
ูุน ุงูู
ุนููู
ุงุช ู
ู ูุฐู ุงููุซููุฉ ุจุตูุบุฉ JSON ู
ูุธู
ุฉ ุชุดู
ู:
- ุฑูู
_ุงูุฃู
ุฑุ ุงูุชุงุฑูุฎุ ุงููุณู
ุ ุงููุฑุฏูุฉ
- ุงุณู
_ุงูุนุงู
ูุ ุงูู
ูู
ุฉุ ุงูุฃููููุฉุ ุงูุญุงูุฉTraining
Run Training
pip install transformers trl torch datasets trackio accelerate peft bitsandbytes qwen-vl-utils
# Set your HF token
export HF_TOKEN=your_token_here
# Run training (needs 24GB+ GPU โ A10G, A6000, or A100)
python train.pyVia HF Jobs
huggingface-cli jobs run train.py \
--hardware a10g-large \
--timeout 6h \
--dependencies transformers trl torch datasets trackio accelerate peft bitsandbytes qwen-vl-utilsHardware Requirements
๐๏ธ Factory Integration
For your factory automation platform:
- PDF Upload โ Convert pages to images (
pdf2imagelibrary) - Extract โ Run this model on each page with work order prompt
- Parse JSON โ Feed structured data to your shift assignment system
- Assign โ Auto-assign shifts based on extracted work order fields
from pdf2image import convert_from_path
# Convert uploaded PDF
pages = convert_from_path("uploaded_work_order.pdf", dpi=200)
# Extract from each page
for page in pages:
result = extract_from_image(model, processor, page, task="work_order")
work_order_data = json.loads(result)
# Feed to your shift assignment system
assign_shifts(work_order_data)Improving Results
For best results on YOUR specific work orders:
- Collect 100-500 annotated examples of your actual work orders with JSON ground truth
- Add them to the training data and re-run fine-tuning
- Use the QARI synthetic pipeline: Render your work order HTML templates โ PDF โ images with Arabic text variations
Related Models & References
- Paper: QARI-OCR (arXiv:2506.02295)
- Paper: AIN (arXiv:2502.00094)
- TRL Docs: SFT VLM Training
