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/api.py from nvidia/Flora-Captioner: direct link, hf CLI and curl.
- Browser
- Download file 3.6 kB
-
https://huggingface.co/nvidia/Flora-Captioner/resolve/refs%2Fpr%2F2/batch_utils/api.py
- Command line
-
hf download hf://nvidia/Flora-Captioner@refs/pr/2/batch_utils/api.py
-
curl -L -o api.py https://huggingface.co/nvidia/Flora-Captioner/resolve/refs%2Fpr%2F2/batch_utils/api.py
3.6 kB
| from pathlib import Path | |
| import math | |
| import threading | |
| from .config import MAX_UPLOAD_BYTES, MODELS | |
| _REQUEST_LOCK = threading.RLock() | |
| _PROFILES = {'human': 'Human', 'yam': 'YAM', 'dex': 'Dex', 'tianji': 'Tianji'} | |
| class DataEnginePipeline: | |
| def _inputs(video, profile, left_wrist, right_wrist, yam32, instruction): | |
| from .media import InputError, probe, check_synchronized | |
| if not isinstance(profile, str) or profile.lower() not in _PROFILES: | |
| raise InputError('profile must be human, yam, dex, or tianji') | |
| canonical = _PROFILES[profile.lower()] | |
| if bool(left_wrist) != bool(right_wrist): | |
| raise InputError('Provide both left and right wrist videos together.') | |
| if canonical == 'Human' and left_wrist: | |
| raise InputError('The human profile accepts one video.') | |
| if not isinstance(yam32, bool): | |
| raise InputError('yam32 must be true or false.') | |
| if yam32 and (canonical != 'YAM' or not left_wrist): | |
| raise InputError('yam32 requires YAM and all three camera views.') | |
| if not isinstance(instruction, str) or len(instruction.strip()) > 2000: | |
| raise InputError('instruction must be a string of at most 2000 characters.') | |
| paths = {'main': video} | |
| if left_wrist: | |
| paths.update(left_wrist=left_wrist, right_wrist=right_wrist) | |
| videos = {} | |
| for role, value in paths.items(): | |
| if not isinstance(value, (str, Path)) or not str(value).strip(): | |
| raise InputError('Each camera path must be a nonempty local path.') | |
| path = Path(value).expanduser().resolve(strict=True) | |
| if not path.is_file() or not 0 < path.stat().st_size <= MAX_UPLOAD_BYTES: | |
| raise InputError('Each input must be a nonempty local video of at most 256 MiB.') | |
| videos[role] = probe(path) | |
| check_synchronized(videos) | |
| return (videos, canonical) | |
| def inspect_inputs(self, video, *, profile='human', left_wrist=None, right_wrist=None, yam32=False, instruction=''): | |
| videos, canonical = self._inputs(video, profile, left_wrist, right_wrist, yam32, instruction) | |
| return {'status': 'inputs_validated', 'profile': canonical, 'yam32': yam32, 'duration_s': videos['main'].duration_s, 'model_revisions': MODELS, 'new_model_calls': 0, 'cameras': {role: {'sha256': v.sha256, 'source_fps': str(v.rate), 'frames': len(v.pts_us), 'size': list(v.size), 'constant_frame_rate': v.cfr, 'duration_s': v.duration_s} for role, v in videos.items()}} | |
| def annotate(self, video, *, profile='human', left_wrist=None, right_wrist=None, yam32=False, instruction='', progress=None, include_audit=False): | |
| import torch | |
| if not torch.cuda.is_available(): | |
| raise RuntimeError('CUDA is required for inference. Use --validate-only to check inputs on CPU.') | |
| from . import pipeline | |
| with _REQUEST_LOCK: | |
| videos, canonical = self._inputs(video, profile, left_wrist, right_wrist, yam32, instruction) | |
| result = pipeline.annotate(videos, canonical, yam32, instruction, progress or (lambda *a, **k: None)) | |
| duration = result['duration_s'] | |
| for segment in result['segments']: | |
| if not (math.isfinite(segment['start_s']) and math.isfinite(segment['end_s']) and (0 <= segment['start_s'] < segment['end_s'] <= duration + 0.001)): | |
| raise RuntimeError('The pipeline returned an invalid caption interval.') | |
| if not include_audit: | |
| result.pop('pipeline', None) | |
| return result | |