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/ordinary_list_completion.py from Cloudflare/clairic-flash: direct link, hf CLI and curl.
- Browser
- Download file 5.66 kB
-
https://huggingface.co/Cloudflare/clairic-flash/resolve/main/clairic_runtime/ordinary_list_completion.py
- Command line
-
hf download hf://Cloudflare/clairic-flash/clairic_runtime/ordinary_list_completion.py
-
curl -L -o ordinary_list_completion.py https://huggingface.co/Cloudflare/clairic-flash/resolve/main/clairic_runtime/ordinary_list_completion.py
5.66 kB
| from __future__ import annotations | |
| from typing import TYPE_CHECKING, Any | |
| from . import batch_completion as shared | |
| from . import schema | |
| if TYPE_CHECKING: | |
| from collections.abc import Callable | |
| from transformers import PreTrainedTokenizerBase | |
| def eligible( | |
| record: dict[str, Any], | |
| tasks: list[tuple[str, list[int], Any]], | |
| kwargs: dict[str, Any], | |
| ) -> bool: | |
| media = kwargs.get("image_data") | |
| object_lists = any( | |
| ( | |
| spec.get("type") == "list" | |
| and isinstance(spec.get("items"), dict) | |
| and (spec["items"].get("type") == "object") | |
| for spec in record.get("fields", {}).values() | |
| ) | |
| ) | |
| guarded = ( | |
| not record.get("_null_recovery") | |
| and (not object_lists) | |
| and ( | |
| record.get("_meta", {}).get("construction") == schema.EVIDENCE_CONSTRUCTION | |
| ) | |
| and (not record.get("_media_payload")) | |
| and (not record.get("_original_images")) | |
| and all((payload is None for (_, _, payload) in tasks)) | |
| and isinstance(media, list) | |
| and (len(media) == len(tasks)) | |
| and all((payload is None for payload in media)) | |
| and ( | |
| not set(kwargs) | |
| - shared._BATCHED_KEYS | |
| - shared._SHARED_KEYS | |
| - {"parse_result", "normalize"} | |
| ) | |
| ) | |
| return guarded and bool( | |
| shared._ordinary_lists(record, tasks, schema.list_item_name) | |
| ) | |
| async def generate( | |
| engine: Any, | |
| record: dict[str, Any], | |
| tasks: list[tuple[str, list[int], Any]], | |
| eos: int, | |
| tokenizer: PreTrainedTokenizerBase, | |
| *, | |
| initial_frontier: int = 0, | |
| next_frontier: int = 0, | |
| parse_result: Callable[..., dict[str, Any]] | None = None, | |
| normalize: Callable[ | |
| [dict[str, Any], dict[str, dict[str, Any]]], dict[str, dict[str, Any]] | |
| ] | |
| | None = None, | |
| **kwargs: Any, | |
| ) -> list[dict[str, Any]]: | |
| enabled = initial_frontier != 0 | |
| if enabled and ( | |
| type(initial_frontier) is not int | |
| or type(next_frontier) is not int | |
| or initial_frontier < 1 | |
| or (next_frontier <= initial_frontier) | |
| ): | |
| raise ValueError( | |
| "Ordinary list scheduling requires positive increasing integer endpoints" | |
| ) | |
| groups = ( | |
| shared._ordinary_lists(record, tasks, schema.list_item_name) | |
| if enabled and eligible(record, tasks, kwargs) | |
| else {} | |
| ) | |
| if not groups: | |
| return await shared.generate( | |
| engine, | |
| record, | |
| tasks, | |
| eos, | |
| tokenizer, | |
| parse_result=parse_result, | |
| normalize=normalize, | |
| **kwargs, | |
| ) | |
| size = len(tasks) | |
| rids = kwargs.get("rid") | |
| if ( | |
| not isinstance(rids, list) | |
| or len(rids) != size | |
| or len(set(rids)) != size | |
| or (not all((isinstance(rid, str) and rid for rid in rids))) | |
| or (kwargs.get("input_ids") != [ids for (_, ids, _) in tasks]) | |
| ): | |
| raise ValueError( | |
| "Ordinary list scheduling requires original distinct task bindings" | |
| ) | |
| shared._select_kwargs(kwargs, list(range(size)), size) | |
| results: list[Any] = [None] * size | |
| unexecuted: dict[str, int] = {} | |
| async def submit(indices: list[int]) -> None: | |
| if not indices: | |
| return | |
| selected = shared._select_kwargs(kwargs, indices, size) | |
| received = await shared._generate( | |
| engine, | |
| record, | |
| [tasks[index] for index in indices], | |
| eos, | |
| tokenizer, | |
| **selected, | |
| ) | |
| if len(received) != len(indices): | |
| raise RuntimeError("Ordinary list scheduling received wrong batch size") | |
| for index, result, rid in zip(indices, received, selected["rid"], strict=True): | |
| if result.get("meta_info", {}).get("id") != rid: | |
| raise RuntimeError( | |
| "Ordinary list scheduling received wrong task identity" | |
| ) | |
| results[index] = result | |
| tails = {index for group in groups.values() for index in group[initial_frontier:]} | |
| await submit([index for index in range(size) if index not in tails]) | |
| active = dict(groups) | |
| (start, end, following) = (0, initial_frontier, next_frontier) | |
| while active: | |
| continued: list[int] = [] | |
| for parent, group in list(active.items()): | |
| stopped = False | |
| for index in group[start:end]: | |
| try: | |
| if shared._completed_null(results[index], eos, tokenizer): | |
| stopped = True | |
| break | |
| except (KeyError, TypeError, ValueError, OverflowError): | |
| continue | |
| if stopped: | |
| for index in group[end:]: | |
| (name, ids, _) = tasks[index] | |
| unexecuted[name] = len(ids) | |
| results[index] = { | |
| "_clair_unused_row_proposal": True, | |
| "_ordinary_list_unexecuted": True, | |
| "meta_info": {"completion_tokens": 0}, | |
| } | |
| del active[parent] | |
| elif end >= len(group): | |
| del active[parent] | |
| else: | |
| continued.extend(group[end:following]) | |
| if continued: | |
| await submit(sorted(continued)) | |
| (start, end, following) = (end, following, following * 2) | |
| if any((result is None for result in results)): | |
| raise RuntimeError("Ordinary list scheduling left an unaccounted result") | |
| record["_unexecuted_list_items"] = unexecuted | |
| return results | |