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/row_omission.py from Cloudflare/clairic-flash: direct link, hf CLI and curl.
- Browser
- Download file 7.5 kB
-
https://huggingface.co/Cloudflare/clairic-flash/resolve/main/clairic_runtime/row_omission.py
- Command line
-
hf download hf://Cloudflare/clairic-flash/clairic_runtime/row_omission.py
-
curl -L -o row_omission.py https://huggingface.co/Cloudflare/clairic-flash/resolve/main/clairic_runtime/row_omission.py
7.5 kB
| """Recover unresolved image rows backed by a completed row inventory.""" | |
| from copy import deepcopy | |
| import json | |
| from typing import Any | |
| from . import ar, image_rows | |
| from .schema import MAX_LIST_ITEMS | |
| def prepare( | |
| record: dict[str, Any], predictions: dict[str, dict[str, Any]] | |
| ) -> tuple[dict[str, Any], list[dict[str, Any]]] | None: | |
| if record.get("_null_recovery") or record.get("_row_omission_recovery"): | |
| return None | |
| annotations = ( | |
| record.get("_meta", {}).get("extraction_contract", {}).get("fields", {}) | |
| ) | |
| tasks = {name: (name, ids, media) for name, ids, media in record["_ar_tasks"]} | |
| if len(tasks) != len(record["_ar_tasks"]): | |
| return None | |
| contexts, retry_tasks = [], [] | |
| constraints = dict(record.get("_ar_constraints", {})) | |
| for parent, annotation in annotations.items(): | |
| queries = annotation.get("image_row_fields") | |
| spec, inventory = record["fields"].get(parent, {}), predictions.get(parent, {}) | |
| value = inventory.get("value") | |
| if ( | |
| set(annotation) != {"image_row_fields"} | |
| or not isinstance(queries, list) | |
| or len(queries) != len(set(queries)) | |
| or not queries | |
| or not image_rows.is_inventory(spec) | |
| or spec.get("knowledge") | |
| or not inventory.get("valid") | |
| or not inventory.get("complete") | |
| or not isinstance(value, list) | |
| or not value | |
| or len(value) > min(spec.get("max_items", MAX_LIST_ITEMS), len(queries)) | |
| or any( | |
| not isinstance(row, dict) | |
| or set(row) != {"label"} | |
| or not isinstance(row["label"], str) | |
| or not row["label"].strip() | |
| for row in value | |
| ) | |
| or any(child not in predictions for child in queries) | |
| ): | |
| continue | |
| properties = spec.get("items", {}).get("properties", {}) | |
| text_keys = [ | |
| key | |
| for key, child in properties.items() | |
| if child.get("type") == "text" and not child.get("knowledge") | |
| ] | |
| if not text_keys: | |
| continue | |
| labels = [row["label"] for row in value] | |
| proposals = [predictions[child] for child in queries] | |
| selected, conflicts = image_rows._select(labels, proposals, text_keys) | |
| if not conflicts or any( | |
| row is not None and (not row.get("valid") or not row.get("complete")) | |
| for row in selected | |
| ): | |
| continue | |
| children, local_constraints = [], {} | |
| for index in conflicts: | |
| child = queries[index] | |
| row, child_spec = predictions[child], record["fields"].get(child, {}) | |
| row_value = row.get("value") | |
| task = tasks.get(child) | |
| native = constraints.get(child, {}) | |
| if ( | |
| annotations.get(child) != {"parent": parent, "index": index + 1} | |
| or child_spec.get("type") != "object" | |
| or not child_spec.get("_image_row_proposal") | |
| or child_spec.get("knowledge") | |
| or not row.get("valid") | |
| or not row.get("complete") | |
| or not isinstance(row_value, dict) | |
| or not row_value | |
| or any(cell is not None for cell in row_value.values()) | |
| or any(row is previous for previous in selected if previous is not None) | |
| or task is None | |
| or task[2] is None | |
| or set(native) != {"json_schema"} | |
| ): | |
| break | |
| schema = json.loads(native["json_schema"]) | |
| if schema != ar.schema(child_spec) or not set(text_keys) <= set( | |
| schema.get("properties", {}) | |
| ): | |
| break | |
| # A completed inventory requires a matching textual cell; the | |
| # original selector remains the acceptance test for that label. | |
| # Full branches retain required fields with the native grammar compiler. | |
| branches = [] | |
| for key in text_keys: | |
| branch = deepcopy(schema) | |
| branch["properties"][key]["type"] = "string" | |
| branches.append(branch) | |
| local_constraints[child] = {"json_schema": json.dumps({"anyOf": branches})} | |
| children.append(child) | |
| else: | |
| constraints.update(local_constraints) | |
| retry_tasks.extend(tasks[child] for child in children) | |
| contexts.append( | |
| { | |
| "parent": parent, | |
| "queries": queries, | |
| "labels": labels, | |
| "text_keys": text_keys, | |
| "selected": selected, | |
| "conflicts": conflicts, | |
| "children": children, | |
| } | |
| ) | |
| if not retry_tasks: | |
| return None | |
| repair = { | |
| **record, | |
| "_ar_tasks": retry_tasks, | |
| "_ar_constraints": constraints, | |
| "_ar_prefix": None, | |
| "_ar_group_prefixes": [], | |
| "_ar_media_groups": [], | |
| "_null_recovery": True, | |
| "_row_omission_recovery": True, | |
| } | |
| return repair, contexts | |
| def merge( | |
| record: dict[str, Any], | |
| predictions: dict[str, dict[str, Any]], | |
| alternatives: dict[str, dict[str, Any]], | |
| plan: tuple[dict[str, Any], list[dict[str, Any]]], | |
| ) -> tuple[dict[str, dict[str, Any]], list[dict[str, Any]]]: | |
| repair, contexts = plan | |
| lengths = {name: len(ids) for name, ids, _ in repair["_ar_tasks"]} | |
| result = dict(predictions) | |
| evidence = [] | |
| for context in contexts: | |
| candidates = {} | |
| for child in context["children"]: | |
| original, alternative = predictions[child], alternatives.get(child, {}) | |
| account = { | |
| "tokens": original["tokens"] + alternative.get("tokens", 0), | |
| "retry_input_tokens": original.get("retry_input_tokens", 0) | |
| + lengths[child], | |
| } | |
| result[child] = {**original, **account} | |
| value = alternative.get("value") | |
| if ( | |
| alternative.get("valid") | |
| and alternative.get("complete") | |
| and isinstance(value, dict) | |
| and any(cell is not None for cell in value.values()) | |
| ): | |
| candidates[child] = { | |
| **alternative, | |
| **account, | |
| "image_row_omission_recovered": True, | |
| } | |
| trial = {**result, **candidates} | |
| selected, conflicts = image_rows._select( | |
| context["labels"], | |
| [trial[name] for name in context["queries"]], | |
| context["text_keys"], | |
| ) | |
| unchanged = all( | |
| previous is None or selected[index] is previous | |
| for index, previous in enumerate(context["selected"]) | |
| ) | |
| accepted = ( | |
| not conflicts and unchanged and len(candidates) == len(context["children"]) | |
| ) | |
| if accepted: | |
| result.update(candidates) | |
| evidence.append( | |
| { | |
| "parent": context["parent"], | |
| "original_conflicts": context["conflicts"], | |
| "retry_children": context["children"], | |
| "conflicts_after_retry": conflicts, | |
| "previously_matched_proposals_preserved_exactly": unchanged, | |
| "accepted": accepted, | |
| } | |
| ) | |
| return result, evidence | |