Text Generation
Transformers
Safetensors
qwen2_5_vl
image-text-to-text
OCR
Text-Generation
Optical-Character-Recognition
Low-Resource-Languages
conversational
text-generation-inference
Instructions to use taresco/KarantaOCR with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use taresco/KarantaOCR with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="taresco/KarantaOCR") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("taresco/KarantaOCR") model = AutoModelForMultimodalLM.from_pretrained("taresco/KarantaOCR", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use taresco/KarantaOCR with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "taresco/KarantaOCR" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "taresco/KarantaOCR", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/taresco/KarantaOCR
- SGLang
How to use taresco/KarantaOCR with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "taresco/KarantaOCR" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "taresco/KarantaOCR", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "taresco/KarantaOCR" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "taresco/KarantaOCR", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use taresco/KarantaOCR with Docker Model Runner:
docker model run hf.co/taresco/KarantaOCR
Update README.md
Browse files
README.md
CHANGED
|
@@ -202,3 +202,29 @@ def run_inference(model, processor, messages, max_new_tokens=128, device="cuda")
|
|
| 202 |
)
|
| 203 |
return outputs[0]
|
| 204 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
)
|
| 203 |
return outputs[0]
|
| 204 |
```
|
| 205 |
+
|
| 206 |
+
### End-to-End Example
|
| 207 |
+
|
| 208 |
+
```python
|
| 209 |
+
model = load_model("taresco/KarantaOCR")
|
| 210 |
+
processor = load_processor("taresco/KarantaOCR")
|
| 211 |
+
|
| 212 |
+
prompt = """Below is the image of one page of a PDF document.
|
| 213 |
+
Just return the plain text representation of this document as if you were reading it naturally.
|
| 214 |
+
Turn equations into a LaTeX representation, and tables into markdown format. Remove the headers and footers, but keep references and footnotes.
|
| 215 |
+
Read any natural handwriting.
|
| 216 |
+
This is likely one page out of several in the document, so be sure to preserve any sentences that come from the previous page, or continue onto the next page, exactly as they are.
|
| 217 |
+
If there is no text at all that you think you should read, you can output null.
|
| 218 |
+
if the document contains diacritics, please include them in the output.
|
| 219 |
+
Do not hallucinate.
|
| 220 |
+
"""
|
| 221 |
+
|
| 222 |
+
messages = build_message(
|
| 223 |
+
image_url="example.pdf",
|
| 224 |
+
system_prompt=prompt,
|
| 225 |
+
page=0
|
| 226 |
+
)
|
| 227 |
+
|
| 228 |
+
output_text = run_inference(model, processor, messages)
|
| 229 |
+
print(output_text)
|
| 230 |
+
```
|