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/identifier_scope.py from Cloudflare/clairic-flash: direct link, hf CLI and curl.
- Browser
- Download file 3.52 kB
-
https://huggingface.co/Cloudflare/clairic-flash/resolve/main/clairic_runtime/identifier_scope.py
- Command line
-
hf download hf://Cloudflare/clairic-flash/clairic_runtime/identifier_scope.py
-
curl -L -o identifier_scope.py https://huggingface.co/Cloudflare/clairic-flash/resolve/main/clairic_runtime/identifier_scope.py
3.52 kB
| from __future__ import annotations | |
| import re | |
| from typing import Any | |
| ROLE_NOTE = " Select the value by its printed label and requested role. Do not infer the role from the spelling or prefix of an identifier. A similar-looking value under another label is not the requested value. Return null if that role is absent." | |
| _GENERIC_NAMES = {"reference", "value"} | |
| _PURCHASE_ORDER = re.compile("\\bpurchase[\\s-]+order\\s+reference\\b", re.IGNORECASE) | |
| _LITERAL = re.compile( | |
| "\\b(?:exact|printed|verbatim|copy|extract|read)\\b", re.IGNORECASE | |
| ) | |
| _EXCLUDED = re.compile( | |
| "\\b(?:not|exclude|excluding|ignore|rather than)\\b[^.;:\\n]*$", re.IGNORECASE | |
| ) | |
| _OTHER_ROLE = re.compile( | |
| "\\b(?:invoice|receipt|payment|tracking|sales[\\s-]+order|account)\\s+(?:reference|number|identifier|id|code)\\b", | |
| re.IGNORECASE, | |
| ) | |
| _TRANSFORM = re.compile( | |
| "\\b(?:compare|combine|join|concatenate|compute|calculate|sum|count|hash|mask|normalize|convert|format|summarize|(?:first|last)\\s+\\d+)\\b", | |
| re.IGNORECASE, | |
| ) | |
| _STATE_TEXT = re.compile( | |
| "\\b(?:state|accompanying)\\s+(?:state\\s+)?text\\b", re.IGNORECASE | |
| ) | |
| _QUOTED_LITERAL_TARGET = re.compile( | |
| "\\b(?:copy|extract|read|return)\\s+(?:the\\s+)?(?:(?:exact|printed|literal|verbatim)\\s+)*(?:phrase|words?|sentence|string)\\s*:?\\s*(?:\"([^\"\\n]+)\"|'([^'\\n]+)'|“([^”\\n]+)”|‘([^’\\n]+)’|`([^`\\n]+)`)", | |
| re.IGNORECASE, | |
| ) | |
| _LITERAL_COMMAND_NEGATION = re.compile( | |
| "\\b(?:never|don['’]t)\\b[^.;:\\n]*$", re.IGNORECASE | |
| ) | |
| def _positive(pattern: re.Pattern[str], instructions: str) -> bool: | |
| return any( | |
| ( | |
| not _EXCLUDED.search(instructions[: match.start()]) | |
| for match in pattern.finditer(instructions) | |
| ) | |
| ) | |
| def _literal_target(instructions: str) -> bool: | |
| for match in _QUOTED_LITERAL_TARGET.finditer(instructions): | |
| prefix = instructions[: match.start()] | |
| if not (_EXCLUDED.search(prefix) or _LITERAL_COMMAND_NEGATION.search(prefix)): | |
| if any( | |
| ( | |
| _PURCHASE_ORDER.search(text) | |
| for text in match.groups() | |
| if text is not None | |
| ) | |
| ): | |
| return True | |
| return False | |
| def prepare_fields( | |
| fields: dict[str, dict[str, Any]], *, has_media: bool | |
| ) -> tuple[dict[str, dict[str, Any]], dict[str, str]]: | |
| if not has_media: | |
| return (fields, {}) | |
| (changed, labels) = ({}, {}) | |
| for name, spec in fields.items(): | |
| if ( | |
| not isinstance(name, str) | |
| or name.casefold() not in _GENERIC_NAMES | |
| or (not isinstance(spec, dict)) | |
| or (spec.get("type") != "text") | |
| or spec.get("knowledge") | |
| or (spec.get("nullable", True) is False) | |
| or ("enum" in spec) | |
| ): | |
| continue | |
| instructions = spec.get("instructions", "") | |
| if ( | |
| not isinstance(instructions, str) | |
| or not _LITERAL.search(instructions) | |
| or _TRANSFORM.search(instructions) | |
| or _STATE_TEXT.search(instructions) | |
| or _literal_target(instructions) | |
| or (not _positive(_PURCHASE_ORDER, instructions)) | |
| or _positive(_OTHER_ROLE, instructions) | |
| ): | |
| continue | |
| if not instructions.endswith(ROLE_NOTE): | |
| changed[name] = {**spec, "instructions": instructions + ROLE_NOTE} | |
| labels[name] = "purchase_order_reference" | |
| return ({**fields, **changed} if changed else fields, labels) | |