Patram-7B-Instruct by BharatGen is a 7B parameter vision-language model trained from scratch for visual document understanding. As India’s first document foundation model, it is built to tackle complex document analysis.
The model was trained on a carefully curated instruction-tuned dataset, combining diverse public and custom synthetic data designed to support a broad spectrum of document understanding tasks.
1import torch
2from transformers import AutoProcessor, AutoModelForCausalLM, GenerationConfig
3from PIL import Image
4import requests
5
6# Model ID and device setup
7model_id = "bharatgenai/patram-7b-instruct"
8device = "cuda" if torch.cuda.is_available() else "cpu"
9
10# Load processor and model
11processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
12model = AutoModelForCausalLM.from_pretrained(
13 model_id,
14 trust_remote_code=True
15).to(device)
16
17def get_patram_response(image_path_or_url, question):
18 try:
19 # Load image
20 if image_path_or_url.startswith("http"):
21 image = Image.open(requests.get(image_path_or_url, stream=True).raw).convert("RGB")
22 else:
23 image = Image.open(image_path_or_url).convert("RGB")
24 except Exception as e:
25 print(f"Error loading image: {e}")
26 return None
27
28 # Format the prompt as expected
29 prompt = f"Question: {question} Answer based on the image."
30
31 try:
32 # Preprocess image and text using the processor
33 inputs = processor.process(images=[image], text=prompt)
34 inputs = {k: v.to(device).unsqueeze(0) for k, v in inputs.items()}
35
36 # Generate output using model's generate_from_batch method (Patram-specific)
37 output = model.generate_from_batch(
38 inputs,
39 GenerationConfig(max_new_tokens=200, stop_strings="<|endoftext|>"),
40 tokenizer=processor.tokenizer
41 )
42
43 # Extract generated tokens (excluding input tokens) and decode
44 generated_tokens = output[0, inputs['input_ids'].size(1):]
45 response = processor.tokenizer.decode(generated_tokens, skip_special_tokens=True).strip()
46 return response
47 except Exception as e:
48 print(f"Error during inference: {e}")
49 return None
50
51# Example usage:
52# image_input = "https://knowscope.in/wp-content/uploads/2025/05/cghd-nag.png"
53# question = "Who issued this notice?"
54# answer = get_patram_response(image_input, question)
55# if answer:
56# print("Answer:", answer)
We evaluated Patram-7B-Instruct alongside other vision-language models (VLMs) in the 7B–9B parameter range across multiple public document benchmarks.
Patram-Bench is an in-house benchmark designed for Indic Document VQA.
*Note: The benchmarked results reflect the API variant.
1@online{BharatGenPatramLaunch2025,
2 author = {{BharatGen Team}},
3 title = {BharatGen Unveils Patram: India's Pioneering Vision-Language Foundation Model for Document Intelligence},
4 year = {2025},
5 url = {https://bharatgen.com/blog/patram-launch},
6 urldate = {2025-06-02}
7}