Image-Text-to-Text
MLX
Safetensors
qwen3_5
clairic
cloudflare
systemone
structured-output
information-extraction
multimodal
custom-code
conversational
4-bit precision
Instructions to use mlx-community/clairic-flash-4bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use mlx-community/clairic-flash-4bit with MLX:
# Make sure mlx-vlm is installed # pip install --upgrade mlx-vlm from mlx_vlm import load, generate from mlx_vlm.prompt_utils import apply_chat_template from mlx_vlm.utils import load_config # Load the model model, processor = load("mlx-community/clairic-flash-4bit") config = load_config("mlx-community/clairic-flash-4bit") # Prepare input image = ["http://images.cocodataset.org/val2017/000000039769.jpg"] prompt = "Describe this image." # Apply chat template formatted_prompt = apply_chat_template( processor, config, prompt, num_images=1 ) # Generate output output = generate(model, processor, formatted_prompt, image) print(output) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Pi
How to use mlx-community/clairic-flash-4bit with Pi:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "mlx-community/clairic-flash-4bit"
Configure the model in Pi
# Install Pi: npm install -g @earendil-works/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "mlx-lm": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "mlx-community/clairic-flash-4bit" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent
How to use mlx-community/clairic-flash-4bit with Hermes Agent:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "mlx-community/clairic-flash-4bit"
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default mlx-community/clairic-flash-4bit
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use mlx-community/clairic-flash-4bit with OpenClaw:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "mlx-community/clairic-flash-4bit"
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:8080/v1 \ --custom-model-id "mlx-community/clairic-flash-4bit" \ --custom-provider-id mlx-lm \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
File size: 5,721 Bytes
ae97c5d | 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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | from __future__ import annotations
from collections.abc import Callable
from typing import TYPE_CHECKING, Any
if TYPE_CHECKING:
from .api import PredictRequest
from .backend import EncodedRequest
import math
import re
from PIL import Image, ImageChops, ImageStat
from .image_focus import focus_document
VIEW_ID = "identifier-content-band-v2"
_ROLE = re.compile(
"\\b(?:invoice|receipt|purchase order|order|tracking|reference|transaction|account|application)\\s+(?:number|identifier|id|code)\\b",
re.IGNORECASE,
)
_EXCLUDED_ROLE = re.compile(
"\\b(?:not|exclude|excluding|ignore|rather than)\\b[^.;:\\n]*$", re.IGNORECASE
)
def _requested_identifier(value: str) -> bool:
return any(
(
not _EXCLUDED_ROLE.search(value[: match.start()])
for match in _ROLE.finditer(value)
)
)
def fields(fields: dict[str, dict[str, Any]]) -> list[str]:
selected = []
for name, spec in fields.items():
if spec.get("type") != "text" or spec.get("knowledge"):
continue
label = re.sub("[_-]+", " ", name)
if _requested_identifier(label) or _requested_identifier(
spec.get("instructions", "")
):
selected.append(name)
return selected
def detail_view(image: Image.Image, *, max_pixels: int = 1600000) -> Image.Image:
return focus_document(image, max_pixels=max_pixels, max_scale=3.0)
def header_view(image: Image.Image, *, max_pixels: int = 1600000) -> Image.Image | None:
if image.mode != "RGB":
return None
if (
ImageChops.difference(
image, Image.new("RGB", image.size, image.getpixel((0, 0)))
).getbbox()
is None
):
return None
header = image.crop((0, 0, image.width, max(1, math.ceil(image.height * 0.4))))
scale = min(3.0, math.sqrt(max_pixels / (header.width * header.height)))
size = (max(1, int(header.width * scale)), max(1, int(header.height * scale)))
return header.resize(size, Image.Resampling.BICUBIC)
def views(
image: Image.Image,
*,
max_pixels: int = 1600000,
unfocused_image: Image.Image | None = None,
) -> tuple[Image.Image, ...]:
focused = (
image
if image is unfocused_image and max_pixels == 1600000
else detail_view(image, max_pixels=max_pixels)
)
if focused is not image:
return (focused,)
header = header_view(image, max_pixels=max_pixels)
return (image, header) if header is not None else (image,)
def content_view(
image: Image.Image, *, max_pixels: int = 1600000
) -> Image.Image | None:
if image.mode != "RGB":
return None
background = tuple(ImageStat.Stat(image.resize((64, 64))).median)
if min(background) < 160:
return None
difference = ImageChops.difference(image, Image.new("RGB", image.size, background))
channels = difference.split()
contrast = ImageChops.lighter(
ImageChops.lighter(channels[0], channels[1]), channels[2]
)
mask = contrast.point(lambda value: 255 if value >= 32 else 0)
bounds = mask.getbbox()
if bounds is None:
return None
(left, top, right, bottom) = bounds
bounds = (
max(0, left - 24),
max(0, top - 24),
min(image.width, right + 24),
min(image.height, bottom + 24),
)
(width, height) = (bounds[2] - bounds[0], bounds[3] - bounds[1])
if width * height > image.width * image.height / 2:
return None
scale = min(3.0, math.sqrt(max_pixels / (width * height)))
if scale <= 1:
return None
return image.crop(bounds).resize(
(max(1, int(width * scale)), max(1, int(height * scale))),
Image.Resampling.BICUBIC,
)
def content_views(
image: Image.Image,
*,
max_pixels: int = 1600000,
unfocused_image: Image.Image | None = None,
) -> tuple[Image.Image, ...]:
selected = (
views(image, max_pixels=max_pixels)
if unfocused_image is None
else views(image, max_pixels=max_pixels, unfocused_image=unfocused_image)
)
if selected[0] is not image:
return selected
content = content_view(image, max_pixels=max_pixels)
return (*selected, content) if content is not None else selected
def prepare(
request: PredictRequest,
encoded: EncodedRequest,
encode: Callable[..., EncodedRequest],
*,
unfocused_image: Image.Image | None = None,
) -> EncodedRequest:
selected = fields(request.fields)
if not selected or len(request.images) != 1 or request.documents:
return encoded
(record, forecasts, tasks, typed, eos) = encoded
child_fields = {name: request.fields[name] for name in selected}
child_request = request.model_copy(update={"fields": child_fields})
def image_views() -> tuple[Image.Image, ...]:
originals = record.get("_original_images")
image: Image.Image = originals[0] if originals else request.images[0].to_pil()
return (
content_views(image, unfocused_image=unfocused_image)
if image is unfocused_image
else content_views(image)
)
(child, _, replacements, _, _) = encode(
child_request, identifier_view=True, image_views=image_views
)
by_name = {task[0]: task for task in replacements}
tasks = [by_name.get(task[0], task) for task in tasks]
salts = dict(record.get("_ar_task_salts", {}))
for name in selected:
record["_ar_constraints"][name] = child["_ar_constraints"][name]
salts[name] = child["_cache_salt"]
record.update(
_ar_tasks=tasks, _ar_task_salts=salts, _ar_prefix=[], _ar_group_prefixes=[]
)
return (record, forecasts, tasks, typed, eos)
|