Image-Text-to-Text
Transformers
Safetensors
qwen3_5
clairic
cloudflare
systemone
multimodal
structured-output
information-extraction
custom-code
conversational
Instructions to use Cloudflare/clairic with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Cloudflare/clairic with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="Cloudflare/clairic") 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") model = AutoModelForMultimodalLM.from_pretrained("Cloudflare/clairic", 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 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Cloudflare/clairic" # 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", "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
- SGLang
How to use Cloudflare/clairic 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" \ --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", "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" \ --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", "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 with Docker Model Runner:
docker model run hf.co/Cloudflare/clairic
Download clairic_runtime/printed_temporal.py from Cloudflare/clairic: direct link, hf CLI and curl.
- Browser
- Download file 6.45 kB
-
https://huggingface.co/Cloudflare/clairic/resolve/main/clairic_runtime/printed_temporal.py
- Command line
-
hf download hf://Cloudflare/clairic/clairic_runtime/printed_temporal.py
-
curl -L -o printed_temporal.py https://huggingface.co/Cloudflare/clairic/resolve/main/clairic_runtime/printed_temporal.py
6.45 kB
| from __future__ import annotations | |
| import re | |
| from datetime import datetime | |
| from typing import Any | |
| TYPES = ("date", "time", "datetime") | |
| COPY_INSTRUCTION = " Copy only a date or time explicitly printed for this exact requested role. Return null if this role has no printed date or time. Do not use invoice or due dates for service or billing period boundaries. Do not infer a period from its duration. Copy the requested date or time exactly as printed, including AM or PM when present. Preserve every digit. Do not normalize or convert the value. Return null only if the requested value is absent." | |
| _LITERAL = re.compile("\\b(?:print\\w*|explicit\\w*|verbatim|shown)\\b", re.IGNORECASE) | |
| _DERIVED = re.compile( | |
| "\\b(?:calculat\\w*|comput\\w*|deriv\\w*|infer\\w*|after|before|ago|next|previous|following|prior|add|subtract|plus|minus|earlier|later|offset|duration|terms)\\b|\\bnet\\s*\\d+\\b|\\b(?:first|last)\\s+day\\s+of\\b", | |
| re.IGNORECASE, | |
| ) | |
| _DOCUMENT_DATE = re.compile( | |
| "\\b(?:invoice|billing|service|subscription|document|receipt)\\b", re.IGNORECASE | |
| ) | |
| _DATE_ROLES = { | |
| "invoice_date", | |
| "due_date", | |
| "period_start", | |
| "period_end", | |
| "start_date", | |
| "end_date", | |
| } | |
| def explicit_fields(fields: dict[str, dict[str, Any]]) -> dict[str, dict[str, Any]]: | |
| result = dict(fields) | |
| for name, spec in fields.items(): | |
| date_list = spec.get("type") == "list" and spec.get("items") == "date" | |
| if ( | |
| spec.get("type") not in TYPES | |
| and (not date_list) | |
| or "source_only" in spec | |
| or "null_threshold" in spec | |
| or spec.get("knowledge") | |
| ): | |
| continue | |
| instructions = spec.get("instructions", "") | |
| if not isinstance(instructions, str): | |
| continue | |
| role = name.casefold() in _DATE_ROLES and _DOCUMENT_DATE.search(instructions) | |
| if (_LITERAL.search(instructions) or role) and ( | |
| not _DERIVED.search(instructions) | |
| ): | |
| result[name] = {**spec, "source_only": True} | |
| return result | |
| def clock(value: str) -> str: | |
| match = re.fullmatch( | |
| "\\s*(\\d{1,2}):(\\d{2})(?::(\\d{2}))?\\s*([AP]\\.?M\\.?)?\\s*", | |
| value, | |
| re.IGNORECASE, | |
| ) | |
| if match is None: | |
| raise ValueError("Unsupported printed time") | |
| (hour, minute, second) = map(int, (match[1], match[2], match[3] or "0")) | |
| meridiem = match[4] | |
| if meridiem: | |
| if not 1 <= hour <= 12: | |
| raise ValueError("Invalid 12-hour clock") | |
| hour = hour % 12 + (12 if meridiem.replace(".", "").upper() == "PM" else 0) | |
| if not 0 <= hour < 24 or not 0 <= minute < 60 or (not 0 <= second < 60): | |
| raise ValueError("Invalid printed time") | |
| return f"{hour:02}:{minute:02}:{second:02}" | |
| def day(value: str) -> str: | |
| value = value.strip() | |
| for fmt in ( | |
| "%Y-%m-%d", | |
| "%Y/%m/%d", | |
| "%Y.%m.%d", | |
| "%B %d, %Y", | |
| "%b %d, %Y", | |
| "%B %d %Y", | |
| "%b %d %Y", | |
| "%d %B %Y", | |
| "%d %b %Y", | |
| ): | |
| try: | |
| return datetime.strptime(value, fmt).date().isoformat() | |
| except ValueError: | |
| pass | |
| numeric = re.fullmatch("(\\d{1,2})([-/.])(\\d{1,2})\\2(\\d{4})", value) | |
| if numeric: | |
| (first, second, year) = (int(numeric[1]), int(numeric[3]), int(numeric[4])) | |
| readings = set() | |
| for month, date in ((first, second), (second, first)): | |
| try: | |
| readings.add(datetime(year, month, date).date().isoformat()) | |
| except ValueError: | |
| pass | |
| if len(readings) == 1: | |
| return readings.pop() | |
| raise ValueError("Unsupported or ambiguous printed date") | |
| def normalize(value: object, kind: str) -> str | None: | |
| if value is None: | |
| return None | |
| if not isinstance(value, str): | |
| raise TypeError("A printed temporal answer must be a string") | |
| if kind == "time": | |
| return clock(value) | |
| if kind == "date": | |
| return day(value) | |
| if kind == "datetime": | |
| match = re.fullmatch( | |
| "(.+?)(?:T|\\s+(?:at\\s+)?)(\\d{1,2}:\\d{2}(?::\\d{2})?\\s*(?:[AP]\\.?M\\.?)?)", | |
| value.strip(), | |
| re.IGNORECASE, | |
| ) | |
| if match is None: | |
| raise ValueError("Unsupported printed datetime") | |
| return day(match[1]) + "T" + clock(match[2]) | |
| raise ValueError("Unsupported temporal type") | |
| def prepare( | |
| fields: dict[str, dict[str, Any]], | |
| ) -> tuple[dict[str, dict[str, Any]], dict[str, str]]: | |
| fields = {name: dict(spec) for (name, spec) in fields.items()} | |
| kinds = {} | |
| for name, spec in fields.items(): | |
| if not spec.get("source_only"): | |
| continue | |
| if spec["type"] == "list" and spec["items"] == "date": | |
| spec["items"] = "text" | |
| spec["instructions"] = spec.get("instructions", "") + COPY_INSTRUCTION | |
| continue | |
| kind = spec["type"] | |
| if kind not in TYPES: | |
| continue | |
| kinds[name] = kind | |
| fields[name] = { | |
| "type": "text", | |
| "nullable": spec.get("nullable", True), | |
| "instructions": spec.get("instructions", "") + COPY_INSTRUCTION, | |
| } | |
| return (fields, kinds) | |
| def normalize_predictions( | |
| record: dict[str, Any], predictions: dict[str, dict[str, Any]] | |
| ) -> dict[str, dict[str, Any]]: | |
| result = dict(predictions) | |
| for name, kind in record.get("_meta", {}).get("printed_temporal", {}).items(): | |
| answer = dict(result[name]) | |
| result[name] = answer | |
| if not answer.get("valid"): | |
| continue | |
| printed = answer["value"] | |
| answer["printed_value"] = printed | |
| if ( | |
| printed is not None | |
| and (not record.get("_media_payload")) | |
| and (not isinstance(printed, str) or printed not in record["input"]) | |
| ): | |
| answer.update( | |
| value=None, | |
| valid=False, | |
| confidence=0.0, | |
| span=None, | |
| failure_reason="not_in_source", | |
| ) | |
| continue | |
| try: | |
| answer["value"] = normalize(printed, kind) | |
| answer["normalization_method"] = "printed_temporal_v1" | |
| except (TypeError, ValueError): | |
| answer.update( | |
| value=None, | |
| valid=False, | |
| confidence=0.0, | |
| failure_reason="invalid_printed_temporal", | |
| ) | |
| return result | |