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
File size: 5,417 Bytes
dc7d8aa | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | """Validation for embedded request images.
Callers translate ``EmbeddedImageError`` into their own validation error type.
The strict mode verifies the complete raster with Pillow; the signature mode
intentionally accepts header-only images for backends that validate only magic
bytes before forwarding the image to another service.
"""
from __future__ import annotations
import base64
import binascii
import io
import re
from collections.abc import Iterable
MAX_IMAGES = 4
MAX_IMAGE_BYTES = 4 * 1024 * 1024
MAX_IMAGES_BYTES = 8 * 1024 * 1024
_STRICT_DATA_URI = re.compile(
r"^data:(image/(?:png|jpe?g|webp));base64,([A-Za-z0-9+/]*={0,2})$", re.IGNORECASE
)
_DATA_URL = re.compile(r"^data:([^;,]+);base64,(.*)$", re.DOTALL)
_FORMATS = {"image/png": "PNG", "image/jpeg": "JPEG", "image/webp": "WEBP"}
class EmbeddedImageError(ValueError):
"""A request-image failure, with a stable code for the serving layer."""
def __init__(self, code: str, message: str) -> None:
super().__init__(message)
self.code = code
def normalize_embedded_image(
value: object,
*,
strict: bool = False,
max_image_bytes: int = MAX_IMAGE_BYTES,
max_pixels: int = 16_000_000,
) -> dict[str, str]:
"""Normalize a data URL or exact ``{content_type, base64}`` object.
``strict=True`` verifies restricted data-URI syntax and complete raster data
with Pillow, including the dimension limit. The default checks image
signatures and accepts a more permissive data-URL syntax.
"""
if isinstance(value, str):
matched = (_STRICT_DATA_URI if strict else _DATA_URL).fullmatch(value)
if matched is None:
label = "URI" if strict else "URL"
raise EmbeddedImageError(
"invalid_image", f"image must be an embedded base64 data {label}"
)
value = {"content_type": matched.group(1), "base64": matched.group(2)}
if type(value) is not dict or set(value) != {"content_type", "base64"}:
raise EmbeddedImageError("invalid_image", "image object has invalid fields")
content_type = value["content_type"]
encoded = value["base64"]
if type(content_type) is not str or type(encoded) is not str:
raise EmbeddedImageError("invalid_image", "image fields must be strings")
canonical_type = content_type.lower().replace("image/jpg", "image/jpeg")
if canonical_type not in _FORMATS:
raise EmbeddedImageError("invalid_image", "image content type is not supported")
try:
decoded = base64.b64decode(encoded, validate=True)
except (binascii.Error, ValueError) as error:
raise EmbeddedImageError(
"invalid_image", "image base64 is malformed"
) from error
if not decoded:
raise EmbeddedImageError("invalid_image", "image payload is empty")
if len(decoded) > max_image_bytes:
raise EmbeddedImageError(
"image_too_large", "image exceeds the decoded byte limit"
)
if strict:
_verify_raster(decoded, _FORMATS[canonical_type], max_pixels=max_pixels)
elif not _has_image_signature(canonical_type, decoded):
raise EmbeddedImageError(
"invalid_image", "image payload does not match its content type"
)
return {
"content_type": canonical_type,
"base64": base64.b64encode(decoded).decode("ascii"),
}
def _verify_raster(data: bytes, expected_format: str, *, max_pixels: int) -> None:
from PIL import Image, UnidentifiedImageError
try:
with Image.open(io.BytesIO(data)) as image:
if image.format != expected_format:
raise EmbeddedImageError(
"invalid_image", "image payload does not match its content type"
)
if image.width * image.height > max_pixels:
raise EmbeddedImageError(
"invalid_image", "image dimensions are too large"
)
image.verify()
except EmbeddedImageError:
raise
except (
UnidentifiedImageError,
OSError,
ValueError,
Image.DecompressionBombError,
) as error:
raise EmbeddedImageError("invalid_image", "image payload is invalid") from error
def _has_image_signature(content_type: str, data: bytes) -> bool:
if content_type == "image/png":
return data.startswith(b"\x89PNG\r\n\x1a\n")
if content_type == "image/jpeg":
return data.startswith(b"\xff\xd8\xff")
return len(data) >= 12 and data.startswith(b"RIFF") and data[8:12] == b"WEBP"
def decoded_base64_size(encoded: str) -> int:
"""Size of already validated, canonical base64 without decoding again."""
return len(encoded) * 3 // 4 - (len(encoded) - len(encoded.rstrip("=")))
def validate_image_count(value: object, *, max_images: int = MAX_IMAGES) -> object:
if not isinstance(value, (list, tuple)):
raise EmbeddedImageError("invalid_image", "images must be an array")
if len(value) > max_images:
raise EmbeddedImageError(
"too_many_images", "request exceeds the image count limit"
)
return value
def validate_total_image_bytes(
sizes: Iterable[int], *, max_bytes: int = MAX_IMAGES_BYTES
) -> None:
if sum(sizes) > max_bytes:
raise EmbeddedImageError(
"images_too_large", "images exceed the aggregate decoded byte limit"
)
|