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/preprocessing.py from nvidia/Flora-Captioner: direct link, hf CLI and curl.
- Browser
- Download file 3.31 kB
-
https://huggingface.co/nvidia/Flora-Captioner/resolve/refs%2Fpr%2F2/batch_utils/preprocessing.py
- Command line
-
hf download hf://nvidia/Flora-Captioner@refs/pr/2/batch_utils/preprocessing.py
-
curl -L -o preprocessing.py https://huggingface.co/nvidia/Flora-Captioner/resolve/refs%2Fpr%2F2/batch_utils/preprocessing.py
3.31 kB
| from fractions import Fraction | |
| import io | |
| import json | |
| from PIL import Image | |
| from .bootstrap import production as a | |
| def instruction_suffix(instruction): | |
| value = instruction.strip() | |
| if not value: | |
| return '' | |
| if len(value) > 2000: | |
| raise ValueError('Keep the optional task instruction below 2000 characters.') | |
| return '\n' + json.dumps({'episode_instruction': value}, ensure_ascii=False, sort_keys=True, separators=(',', ':'), allow_nan=False) | |
| def human_transport(frames): | |
| from flora_runtime.exact_frame_serving import encode_regularized_image | |
| output = {} | |
| for index, image in frames.items(): | |
| payload = encode_regularized_image(image, encoding='jpeg_q98_444')['payload'] | |
| with Image.open(io.BytesIO(payload)) as decoded: | |
| output[index] = decoded.convert('RGB') | |
| return output | |
| def temporal_inputs(frames, window, pool, proc, roles, instruction=''): | |
| from transformers.video_utils import VideoMetadata | |
| from flora_runtime.exact_frame_serving import regularized_resize_dims | |
| profile = window.window_profile | |
| if len(frames) != profile.slot_count: | |
| raise ValueError('Incorrect native temporal slot count') | |
| regularized = [] | |
| for image in frames: | |
| image = image.convert('RGB') | |
| height, width = regularized_resize_dims(height=image.height, width=image.width, min_pixels=256, max_pixels=40000 if len(roles) == 1 else 160000) | |
| if image.size != (width, height): | |
| image = image.resize((width, height), Image.Resampling.BICUBIC) | |
| regularized.append(image) | |
| prompt = a.temporal_prompt(window, pool) + instruction_suffix(instruction) | |
| text = proc.apply_chat_template([dict(role='user', content=prompt.replace('<video>', proc.video_token))], tokenize=False, add_generation_prompt=True, enable_thinking=False) | |
| inputs = proc(text=[text], videos=[regularized], video_metadata=[VideoMetadata(total_num_frames=profile.slot_count, fps=profile.slot_fps, frames_indices=list(range(profile.slot_count)))], do_sample_frames=False, return_metadata=True, return_tensors='pt') | |
| inputs.pop('video_metadata', None) | |
| return (inputs, text) | |
| def three_view_caption_inputs(plan, frames, proc, instruction=''): | |
| from transformers.video_utils import VideoMetadata | |
| from plans import HEADING, INSTRUCTION | |
| time_base = Fraction(plan['time_base']) | |
| content, videos, metadata = ([HEADING], [], []) | |
| for block in plan['blocks']: | |
| times = ', '.join((f'{float(t * time_base):.9f}' for t in block['pts_ticks'])) | |
| content.append(block['role'] + ':\nFrames are in this order; native source timestamps in seconds: [' + times + '].\n' + proc.video_token) | |
| videos.append([frames[i] for i in block['indices']]) | |
| metadata.append(VideoMetadata(total_num_frames=len(block['indices']), fps=float(Fraction(plan['clock_fps'])), frames_indices=[i - block['source_start_frame'] for i in block['indices']])) | |
| content.append(INSTRUCTION + instruction_suffix(instruction)) | |
| text = proc.apply_chat_template([dict(role='user', content=''.join(content))], tokenize=False, add_generation_prompt=True, enable_thinking=False) | |
| result = proc(text=[text], videos=videos, video_metadata=metadata, do_sample_frames=False, return_tensors='pt', padding=True) | |
| return (result, text) | |