Image-Text-to-Text
Transformers
Safetensors
qwen3_5
clairic
cloudflare
systemone
multimodal
structured-output
information-extraction
custom-code
conversational
Instructions to use Cloudflare/clairic with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Cloudflare/clairic with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="Cloudflare/clairic") 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("Cloudflare/clairic") model = AutoModelForMultimodalLM.from_pretrained("Cloudflare/clairic", 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 Cloudflare/clairic with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Cloudflare/clairic" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Cloudflare/clairic", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/Cloudflare/clairic
- SGLang
How to use Cloudflare/clairic 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 "Cloudflare/clairic" \ --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": "Cloudflare/clairic", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'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 "Cloudflare/clairic" \ --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": "Cloudflare/clairic", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use Cloudflare/clairic with Docker Model Runner:
docker model run hf.co/Cloudflare/clairic
Download clairic_runtime/orientation.py from Cloudflare/clairic: direct link, hf CLI and curl.
- Browser
- Download file 3.18 kB
-
https://huggingface.co/Cloudflare/clairic/resolve/main/clairic_runtime/orientation.py
- Command line
-
hf download hf://Cloudflare/clairic/clairic_runtime/orientation.py
-
curl -L -o orientation.py https://huggingface.co/Cloudflare/clairic/resolve/main/clairic_runtime/orientation.py
3.18 kB
| """Conservative page orientation from detached dots beside Latin letter stems. | |
| This examines glyph geometry only; it performs no text readout. Pages without | |
| enough consistent evidence retain their supplied orientation. | |
| """ | |
| from __future__ import annotations | |
| from typing import TYPE_CHECKING | |
| if TYPE_CHECKING: | |
| from PIL import Image | |
| def document_rotation(image: Image.Image) -> tuple[int, list[int]]: | |
| import cv2 | |
| import numpy as np | |
| page = image.convert("L") | |
| page.thumbnail((1600, 1600)) | |
| pixels = np.asarray(page) | |
| _, ink = cv2.threshold(pixels, 0, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU) | |
| _, _, stats, _ = cv2.connectedComponentsWithStats(ink, connectivity=8) | |
| stats = stats[1:] | |
| votes = [0, 0, 0, 0] | |
| if not len(stats) or len(stats) > 12_000: | |
| return 0, votes | |
| width, height, area = stats[:, 2:].T | |
| short, long = np.minimum(width, height), np.maximum(width, height) | |
| stems = stats[(long >= 9) & (long <= 60) & (long >= 2.5 * short) & (area >= 8)] | |
| dots = stats[(width <= 12) & (height <= 12) & (area >= 2) & (area <= 100)] | |
| if not len(stems) or not len(dots) or len(stems) > 1200 or len(dots) > 2400: | |
| return 0, votes | |
| dx, dy, dw, dh, da = dots.T | |
| for sx, sy, sw, sh, sa in stems: | |
| vertical = sh > sw | |
| across = dx + dw / 2 if vertical else dy + dh / 2 | |
| center = sx + sw / 2 if vertical else sy + sh / 2 | |
| start, length = (sy, sh) if vertical else (sx, sw) | |
| left, size = (dy, dh) if vertical else (dx, dw) | |
| thin = sw if vertical else sh | |
| aligned = (abs(across - center) <= max(1.5, thin * 0.6)) & ( | |
| size <= length * 0.4 | |
| ) | |
| aligned &= (dw <= max(3, thin * 2)) if vertical else (dh <= max(3, thin * 2)) | |
| aligned &= da < sa * 0.7 | |
| before = ( | |
| aligned & (left + size <= start) & (start - left - size <= length * 0.45) | |
| ) | |
| after = ( | |
| aligned | |
| & (left >= start + length) | |
| & (left - start - length <= length * 0.45) | |
| ) | |
| if vertical: | |
| votes[0] += int(np.any(before)) | |
| votes[2] += int(np.any(after)) | |
| else: | |
| votes[1] += int(np.any(before)) | |
| votes[3] += int(np.any(after)) | |
| letters = (area >= 10) & (short >= 3) & (long <= 60) & (long <= 4 * short) | |
| if int(letters.sum()) < 80: | |
| return 0, votes | |
| aspect = float(np.median(width[letters] / height[letters])) | |
| if aspect < 0.8: | |
| directions = (0, 2) | |
| elif aspect > 1.25: | |
| directions = (1, 3) | |
| else: | |
| return 0, votes | |
| # Text-line direction excludes accidental dot/stem pairs in the other axis. | |
| winner = max(directions, key=votes.__getitem__) | |
| runner = votes[directions[0] if winner == directions[1] else directions[1]] | |
| if ( | |
| votes[winner] < 12 | |
| or votes[winner] < 3 * max(1, runner) | |
| or votes[winner] < 0.7 * (votes[winner] + runner) | |
| ): | |
| return 0, votes | |
| return winner * 90, votes | |
| def orient_document(image: Image.Image) -> Image.Image: | |
| rotation, _ = document_rotation(image) | |
| return image.rotate(-rotation, expand=True) if rotation else image | |