Run this model with HF Jobs

Run nvidia/Cosmos3-Super-Text2Image-4Step on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs to fine-tune https://huggingface.co/nvidia/Cosmos3-Super-Text2Image-4Step. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/nvidia/Cosmos3-Super-Text2Image-4Step on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Raw History Blame
2.07 kB
"""Minimal text-to-image generation against a vLLM-Omni endpoint.
Run from the Cosmos3-Super-Text2Image-4Step repo root:
python scripts/gen_image.py \
--prompt-file assets/example_caption.json \
--output-path scripts/output.png
Use --endpoint http://<server-host>:8000 if the vLLM-Omni server is not local.
"""
import argparse
import base64
import json
from pathlib import Path
import requests
# Fixed generation settings: square 768px image.
WIDTH = 768
HEIGHT = 768
def main() -> None:
parser = argparse.ArgumentParser(description="Generate one T2I sample.")
parser.add_argument("--endpoint", default="http://localhost:8000", help="vLLM-Omni endpoint base URL.")
parser.add_argument("--prompt-file", type=Path, default=Path("assets/example_caption.json"))
parser.add_argument("--output-path", type=Path, default=Path("scripts/output.png"))
args = parser.parse_args()
json_prompt = json.loads(args.prompt_file.read_text(encoding="utf-8"))
json_prompt["resolution"] = {"H": HEIGHT, "W": WIDTH}
json_prompt["aspect_ratio"] = "1,1"
request_body = {
"prompt": json.dumps(json_prompt, ensure_ascii=False),
"size": f"{WIDTH}x{HEIGHT}",
"n": 1,
"guidance_scale": 1.0,
"negative_prompt": "",
"seed": 1143,
"extra_args": {
"guardrails": True,
"use_resolution_template": False,
},
}
endpoint = args.endpoint.rstrip("/")
response = requests.post(
f"{endpoint}/v1/images/generations",
json=request_body,
headers={"Content-Type": "application/json"},
timeout=(10, 600),
)
response.raise_for_status()
response_json = response.json()
b64_data = response_json["data"][0]["b64_json"]
image_bytes = base64.b64decode(b64_data)
args.output_path.parent.mkdir(parents=True, exist_ok=True)
args.output_path.write_bytes(image_bytes)
print(f"Saved image to {args.output_path} ({len(image_bytes) / (1024 * 1024):.1f} MB)")
if __name__ == "__main__":
main()