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/contracts.py from Cloudflare/clairic-flash: direct link, hf CLI and curl.
- Browser
- Download file 6.11 kB
-
https://huggingface.co/Cloudflare/clairic-flash/resolve/main/clairic_runtime/contracts.py
- Command line
-
hf download hf://Cloudflare/clairic-flash/clairic_runtime/contracts.py
-
curl -L -o contracts.py https://huggingface.co/Cloudflare/clairic-flash/resolve/main/clairic_runtime/contracts.py
6.11 kB
| from __future__ import annotations | |
| from typing import Any | |
| from jsonschema import Draft202012Validator, SchemaError | |
| COMMON = {"type", "instructions", "nullable"} | |
| NUMERIC = {"integer", "decimals", "unit"} | |
| GRAMMAR_NUMBER = {"minimum", "maximum", "exclusiveMinimum", "exclusiveMaximum", "enum"} | |
| OPTIONS = { | |
| "text": {"knowledge", "minLength", "maxLength", "pattern", "enum"}, | |
| "number": NUMERIC | GRAMMAR_NUMBER | {"knowledge", "source_only"}, | |
| "compute": NUMERIC | {"null_threshold"}, | |
| "date": {"null_threshold", "source_only"}, | |
| "time": {"null_threshold", "source_only"}, | |
| "datetime": {"null_threshold", "source_only"}, | |
| "duration": NUMERIC | {"null_threshold"}, | |
| "boolean": set(), | |
| "enum": {"enum"}, | |
| "object": {"properties"}, | |
| "list": {"items", "max_items", "knowledge", "source_only"} | NUMERIC | {"enum"}, | |
| "estimate": {"min", "max", "scale", "step", "unit"}, | |
| "forecast": {"min", "max", "scale", "step", "unit", "horizon", "interval"}, | |
| } | |
| def item_spec(spec: dict[str, Any]) -> dict[str, Any]: | |
| item = spec["items"] | |
| return dict(item) if isinstance(item, dict) else {"type": item} | |
| def validate_public_fields(fields: dict[str, dict[str, Any]]) -> None: | |
| _validate_public_fields(fields, set()) | |
| def _validate_public_fields( | |
| fields: dict[str, dict[str, Any]], checked_scalar_schemas: set[tuple[str, ...]] | |
| ) -> None: | |
| for name, spec in fields.items(): | |
| kind = spec.get("type") if isinstance(spec, dict) else None | |
| if not isinstance(kind, str) or kind not in OPTIONS: | |
| raise ValueError(f"field {name}: unknown field type") | |
| unknown = spec.keys() - COMMON - OPTIONS[kind] | |
| if unknown: | |
| raise ValueError(f"field {name}: unknown options {sorted(unknown)}") | |
| if "instructions" in spec and (not isinstance(spec["instructions"], str)): | |
| raise ValueError(f"field {name}: instructions must be a string") | |
| if "nullable" in spec and (not isinstance(spec["nullable"], bool)): | |
| raise ValueError(f"field {name}: nullable must be true or false") | |
| if "source_only" in spec: | |
| if not isinstance(spec["source_only"], bool): | |
| raise ValueError(f"field {name}: source_only must be true or false") | |
| if kind == "list" and spec.get("items") not in ("date", "number"): | |
| raise ValueError( | |
| f"field {name}: source_only lists require date or number items" | |
| ) | |
| if spec["source_only"] and "null_threshold" in spec: | |
| raise ValueError( | |
| f"field {name}: source_only does not support typed null_threshold" | |
| ) | |
| if spec["source_only"] and spec.get("knowledge"): | |
| raise ValueError( | |
| f"field {name}: source_only cannot permit knowledge answers" | |
| ) | |
| if "enum" in spec and (not isinstance(spec["enum"], list) or not spec["enum"]): | |
| raise ValueError(f"field {name}: enum must be a nonempty array") | |
| if kind == "enum" and "enum" not in spec: | |
| raise ValueError(f"field {name}: enum values are required") | |
| if kind == "object": | |
| properties = spec.get("properties") | |
| if not isinstance(properties, dict) or not properties: | |
| raise ValueError(f"field {name}: object properties are required") | |
| if any( | |
| ( | |
| not isinstance(child, dict) | |
| or child.get("type") not in ("text", "number", "boolean", "enum") | |
| for child in properties.values() | |
| ) | |
| ): | |
| raise ValueError( | |
| f"field {name}: row properties must be text, number, boolean or enum" | |
| ) | |
| if any((child.get("source_only") for child in properties.values())): | |
| raise ValueError( | |
| f"field {name}: source_only is supported on scalar numbers and number lists, not row properties" | |
| ) | |
| _validate_public_fields(properties, checked_scalar_schemas) | |
| from . import schema as zs | |
| zs.validate_fields(properties) | |
| if kind == "list": | |
| if "items" not in spec: | |
| raise ValueError(f"list {name}: items are required") | |
| child = item_spec(spec) | |
| if isinstance(spec["items"], dict) and child.get("type") != "object": | |
| raise ValueError(f"list {name}: structured items must be objects") | |
| if child.get("type") == "object": | |
| _validate_public_fields({name + "[]": child}, checked_scalar_schemas) | |
| if spec.keys() & (NUMERIC | {"knowledge", "enum"}): | |
| raise ValueError( | |
| f"list {name}: put numeric or knowledge options on row properties" | |
| ) | |
| maximum = spec.get("max_items") | |
| if "max_items" in spec and ( | |
| isinstance(maximum, bool) or not isinstance(maximum, int) or maximum < 0 | |
| ): | |
| raise ValueError( | |
| f"list {name}: max_items must be a nonnegative integer" | |
| ) | |
| if kind in ("text", "number", "boolean", "enum", "object"): | |
| from . import ar | |
| try: | |
| schema = ar.schema(spec) | |
| scalar_key = None | |
| if schema.keys() == {"type"}: | |
| schema_type = schema["type"] | |
| scalar_key = ( | |
| tuple(schema_type) | |
| if isinstance(schema_type, list) | |
| else (schema_type,) | |
| ) | |
| if scalar_key is None or scalar_key not in checked_scalar_schemas: | |
| Draft202012Validator.check_schema(schema) | |
| if scalar_key is not None: | |
| checked_scalar_schemas.add(scalar_key) | |
| except SchemaError as error: | |
| raise ValueError( | |
| f"field {name}: invalid schema constraint: {error.message}" | |
| ) from error | |