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/media.py from Cloudflare/clairic-flash: direct link, hf CLI and curl.
- Browser
- Download file 3.41 kB
-
https://huggingface.co/Cloudflare/clairic-flash/resolve/main/clairic_runtime/media.py
- Command line
-
hf download hf://Cloudflare/clairic-flash/clairic_runtime/media.py
-
curl -L -o media.py https://huggingface.co/Cloudflare/clairic-flash/resolve/main/clairic_runtime/media.py
3.41 kB
| from __future__ import annotations | |
| from collections.abc import Sequence | |
| from typing import Any | |
| def batch_image_data(media: Sequence[Any]) -> list[Any]: | |
| if all((item is None for item in media)): | |
| return list(media) | |
| return [item if item is not None else [] for item in media] | |
| def _grid_identity(grid: Any) -> Any: | |
| if hasattr(grid, "tolist"): | |
| grid = grid.tolist() | |
| if isinstance(grid, (list, tuple)): | |
| return tuple((_grid_identity(value) for value in grid)) | |
| if isinstance(grid, (str, int, float, bool, type(None))): | |
| return grid | |
| return ("opaque", id(grid)) | |
| def _media_identity(media: Any) -> tuple[Any, ...]: | |
| if media is None: | |
| return ("text",) | |
| if not isinstance(media, list) or not media: | |
| return ("opaque", id(media)) | |
| identities = [] | |
| for item in media: | |
| if ( | |
| not isinstance(item, dict) | |
| or item.get("format") != "processor_output" | |
| or (not isinstance(item.get("clair_media_digest"), str)) | |
| or (item.get("pixel_values") is None) | |
| ): | |
| return ("opaque", id(media)) | |
| identities.append( | |
| ( | |
| item["clair_media_digest"], | |
| id(item["pixel_values"]), | |
| _grid_identity(item.get("image_grid_thw")), | |
| ) | |
| ) | |
| return ("prepared", tuple(identities)) | |
| def _common_prefix(tasks: list[tuple[str, list[int], Any]]) -> list[int]: | |
| (first, last) = (min((task[1] for task in tasks)), max((task[1] for task in tasks))) | |
| length = next( | |
| (i for (i, (left, right)) in enumerate(zip(first, last)) if left != right), | |
| min(len(first), len(last)), | |
| ) | |
| return list(first[:length]) | |
| def media_warmup_groups( | |
| tasks: list[tuple[str, list[int], Any]], | |
| *, | |
| default_salt: str, | |
| task_salts: dict[str, str] | None = None, | |
| annotations: dict[str, dict[str, Any]] | None = None, | |
| min_prefix_tokens: int = 128, | |
| ) -> list[dict[str, Any]]: | |
| (task_salts, annotations) = (task_salts or {}, annotations or {}) | |
| partitions: dict[tuple[str, tuple[Any, ...]], dict[str, Any]] = {} | |
| for task in tasks: | |
| (name, _, media) = task | |
| salt = task_salts.get(name, default_salt) | |
| key = (salt, _media_identity(media)) | |
| partitions.setdefault(key, {"media": media, "salt": salt, "tasks": []})[ | |
| "tasks" | |
| ].append(task) | |
| records = [] | |
| for partition in partitions.values(): | |
| members = partition["tasks"] | |
| if len(members) < 2: | |
| continue | |
| prefix = _common_prefix(members) | |
| if len(prefix) < min_prefix_tokens: | |
| prefix = [] | |
| parents: dict[str, list[tuple[str, list[int], Any]]] = {} | |
| for task in members: | |
| parent = annotations.get(task[0], {}).get("parent") | |
| if parent: | |
| parents.setdefault(parent, []).append(task) | |
| subgroups = [ | |
| _common_prefix(group) for group in parents.values() if len(group) > 1 | |
| ] | |
| subgroups = [group for group in subgroups if group and group != prefix] | |
| if prefix or subgroups: | |
| records.append( | |
| { | |
| "prefix_ids": prefix, | |
| "media": partition["media"], | |
| "salt": partition["salt"], | |
| "group_prefix_ids": subgroups, | |
| } | |
| ) | |
| return records | |