Instructions to use APMIC/trocr-printed-model with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use APMIC/trocr-printed-model with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="APMIC/trocr-printed-model")# Load model directly from transformers import AutoTokenizer, AutoModelForMultimodalLM tokenizer = AutoTokenizer.from_pretrained("APMIC/trocr-printed-model") model = AutoModelForMultimodalLM.from_pretrained("APMIC/trocr-printed-model", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use APMIC/trocr-printed-model with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "APMIC/trocr-printed-model" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "APMIC/trocr-printed-model", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/APMIC/trocr-printed-model
- SGLang
How to use APMIC/trocr-printed-model 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 "APMIC/trocr-printed-model" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "APMIC/trocr-printed-model", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "APMIC/trocr-printed-model" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "APMIC/trocr-printed-model", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use APMIC/trocr-printed-model with Docker Model Runner:
docker model run hf.co/APMIC/trocr-printed-model
| !pip install transformers | |
| from transformers import TrOCRProcessor, VisionEncoderDecoderModel | |
| from PIL import Image | |
| import requests | |
| url = 'https://fki.tic.heia-fr.ch/static/img/a01-122-02-00.jpg' | |
| processor = TrOCRProcessor.from_pretrained('JerryWu/trocr-printed-model') | |
| model = VisionEncoderDecoderModel.from_pretrained('JerryWu/trocr-printed-model') | |
| pixel_values = processor(images=image, return_tensors="pt").pixel_values | |
| image = Image.open(requests.get(url, stream=True).raw).convert("RGB") | |
| generated_ids = model.generate(pixel_values) | |
| generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0] | |
| print(generated_text) |