Image-Text-to-Text
Transformers
Safetensors
qwen3_5
clairic
cloudflare
systemone
multimodal
structured-output
information-extraction
custom-code
conversational
Instructions to use Cloudflare/clairic-flash with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Cloudflare/clairic-flash with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="Cloudflare/clairic-flash") 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-flash") model = AutoModelForMultimodalLM.from_pretrained("Cloudflare/clairic-flash", 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-flash with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Cloudflare/clairic-flash" # 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-flash", "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-flash
- SGLang
How to use Cloudflare/clairic-flash 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-flash" \ --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-flash", "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-flash" \ --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-flash", "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-flash with Docker Model Runner:
docker model run hf.co/Cloudflare/clairic-flash
Download clairic_runtime/image_party_names.py from Cloudflare/clairic-flash: direct link, hf CLI and curl.
- Browser
- Download file 2.68 kB
-
https://huggingface.co/Cloudflare/clairic-flash/resolve/main/clairic_runtime/image_party_names.py
- Command line
-
hf download hf://Cloudflare/clairic-flash/clairic_runtime/image_party_names.py
-
curl -L -o image_party_names.py https://huggingface.co/Cloudflare/clairic-flash/resolve/main/clairic_runtime/image_party_names.py
2.68 kB
| from __future__ import annotations | |
| import math | |
| import re | |
| from typing import Any | |
| import numpy as np | |
| from PIL import Image, ImageChops | |
| VIEW_ID = "party-name-header-lines-v1" | |
| VIEW_INSTRUCTION = " The first image is the complete document. The second image enlarges its first printed lines. Use both views of the same source to read the complete requested name; preserve every digit in the name." | |
| _ROLE = re.compile( | |
| "\\b(?:seller|merchant|vendor|customer|bill[- ]?to|recipient|payee|payer|guest|organization|business|company|legal)\\b", | |
| re.IGNORECASE, | |
| ) | |
| _OTHER_VALUE = re.compile( | |
| "\\b(?:address|number|identifier|code|date|row|label|amount)\\b", re.IGNORECASE | |
| ) | |
| def fields(schema: dict[str, dict[str, Any]]) -> list[str]: | |
| selected = [] | |
| for name, spec in schema.items(): | |
| instructions = spec.get("instructions", "") | |
| if ( | |
| spec.get("type") != "text" | |
| or spec.get("knowledge") | |
| or (not isinstance(instructions, str)) | |
| ): | |
| continue | |
| requested = re.split("[.\\n]", instructions, maxsplit=1)[0] | |
| if ( | |
| re.search("\\bname\\b", requested, re.IGNORECASE) | |
| and _ROLE.search(requested) | |
| and (not _OTHER_VALUE.search(requested)) | |
| ): | |
| selected.append(name) | |
| return selected | |
| def header_detail( | |
| image: Image.Image, *, max_pixels: int = 1600000 | |
| ) -> Image.Image | None: | |
| if image.mode != "RGB" or image.getpixel((0, 0)) != (255, 255, 255): | |
| return None | |
| ink = np.asarray(image.convert("L")) < 200 | |
| if np.mean(ink) > 0.22: | |
| return None | |
| edges = np.flatnonzero(np.diff(np.pad(ink.any(axis=1).astype(np.int8), (1, 1)))) | |
| bands = edges.reshape(-1, 2).tolist()[:6] | |
| if not bands or any((not 8 <= bottom - top <= 32 for (top, bottom) in bands)): | |
| return None | |
| top = max(0, bands[0][0] - 24) | |
| bottom = min(image.height, bands[-1][1] + 24) | |
| block = image.crop((0, top, image.width, bottom)) | |
| bounds = ImageChops.difference( | |
| block, Image.new("RGB", block.size, "white") | |
| ).getbbox() | |
| if bounds is None: | |
| return None | |
| (left, right) = (max(0, bounds[0] - 24), min(block.width, bounds[2] + 24)) | |
| block = block.crop((left, 0, right, block.height)) | |
| scale = min(3.0, math.sqrt(max_pixels / (block.width * block.height))) | |
| size = (max(1, int(block.width * scale)), max(1, int(block.height * scale))) | |
| return block.resize(size, Image.Resampling.BICUBIC) | |
| def views(image: Image.Image, *, max_pixels: int = 1600000) -> tuple[Image.Image, ...]: | |
| detail = header_detail(image, max_pixels=max_pixels) | |
| return (image, detail) if detail is not None else (image,) | |