Image-Text-to-Text
Transformers
Safetensors
qwen3_5
qwen3.5
video
video-captioning
data-engine
conversational
Instructions to use nvidia/Flora-Captioner with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use nvidia/Flora-Captioner with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="nvidia/Flora-Captioner") 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("nvidia/Flora-Captioner") model = AutoModelForMultimodalLM.from_pretrained("nvidia/Flora-Captioner", 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 nvidia/Flora-Captioner with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "nvidia/Flora-Captioner" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nvidia/Flora-Captioner", "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/nvidia/Flora-Captioner
- SGLang
How to use nvidia/Flora-Captioner 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 "nvidia/Flora-Captioner" \ --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": "nvidia/Flora-Captioner", "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 "nvidia/Flora-Captioner" \ --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": "nvidia/Flora-Captioner", "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 nvidia/Flora-Captioner with Docker Model Runner:
docker model run hf.co/nvidia/Flora-Captioner
Download batch_utils/vendor/robot_caption_geometry.py from nvidia/Flora-Captioner: direct link, hf CLI and curl.
- Browser
- Download file 2.74 kB
-
https://huggingface.co/nvidia/Flora-Captioner/resolve/main/batch_utils/vendor/robot_caption_geometry.py
- Command line
-
hf download hf://nvidia/Flora-Captioner/batch_utils/vendor/robot_caption_geometry.py
-
curl -L -o robot_caption_geometry.py https://huggingface.co/nvidia/Flora-Captioner/resolve/main/batch_utils/vendor/robot_caption_geometry.py
2.74 kB
| import hashlib, io | |
| from PIL import Image | |
| PACKED_IMAGE_LIMIT_BYTES = 21_866_496 | |
| SCALES = [1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2] | |
| def sha(b): | |
| return hashlib.sha256(b).hexdigest() | |
| def png(im): | |
| b = io.BytesIO() | |
| im.save(b, format='PNG', compress_level=1, optimize=False) | |
| return b.getvalue() | |
| def normalized(plan, frames, expected=None): | |
| factors = [expected['common_geometry']['scale']] if expected else SCALES | |
| for factor in factors: | |
| blocks = [] | |
| count = 0 | |
| for block in plan['blocks']: | |
| assets = [] | |
| for start in range(0, len(block['indices']), 2): | |
| indices = block['indices'][start:start + 2] | |
| originals = [frames[i] for i in indices] | |
| w, h = originals[0].size | |
| nw = round(w * factor) | |
| nh = round(h * factor) | |
| packed = Image.new('RGB', (nw * len(indices), nh)) | |
| rgb = [] | |
| for pos, image in enumerate(originals): | |
| if factor != 1: | |
| image = image.resize((nw, nh), Image.Resampling.LANCZOS) | |
| packed.paste(image, (pos * nw, 0)) | |
| rgb.append(sha(image.tobytes())) | |
| blob = png(packed) | |
| count += len(blob) + (-len(blob) % 3) | |
| assets.append(dict(indices=indices, size=list(packed.size), sha256=sha(blob), rgb_sha256=rgb, bytes=len(blob), _blob=blob)) | |
| blocks.append(dict(role=block['role'], images=assets)) | |
| if count <= PACKED_IMAGE_LIMIT_BYTES: | |
| break | |
| else: | |
| raise RuntimeError('No common caption input geometry fits') | |
| if expected: | |
| for old, new in zip(expected['frame_blocks'], blocks): | |
| assert old['role'] == new['role'] and len(old['images']) == len(new['images']) | |
| for a, b in zip(old['images'], new['images']): | |
| assert a['indices'] == b['indices'] and a['rgb_sha256'] == b['rgb_sha256'] and (a['size'] == b['size']) | |
| return dict(plan, frame_blocks=blocks, common_geometry=dict(scale=factor, source_pixel_unchanged=factor == 1, aligned_image_bytes=count, image_size_limit_bytes=PACKED_IMAGE_LIMIT_BYTES, sampling_frames_removed=0)) | |
| def source_frames(normalized): | |
| out = {} | |
| for block in normalized['frame_blocks']: | |
| for a in block['images']: | |
| image = Image.open(io.BytesIO(a['_blob'])).convert('RGB') | |
| n = len(a['indices']) | |
| w = image.width // n | |
| for pos, i in enumerate(a['indices']): | |
| frame = image.crop((pos * w, 0, (pos + 1) * w, image.height)) | |
| assert sha(frame.tobytes()) == a['rgb_sha256'][pos] | |
| out[i] = frame | |
| return out | |