Text-to-Image
MiniMax H3
Diffusers
Safetensors
English
image-to-image
image-editing
image-generation
Instructions to use MiniMaxAI/MiniMax-H3-Image with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use MiniMaxAI/MiniMax-H3-Image with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("MiniMaxAI/MiniMax-H3-Image", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
Download examples/t2i.py from MiniMaxAI/MiniMax-H3-Image: direct link, hf CLI and curl.
- Browser
- Download file 1.79 kB
-
https://huggingface.co/MiniMaxAI/MiniMax-H3-Image/resolve/main/examples/t2i.py
- Command line
-
hf download hf://MiniMaxAI/MiniMax-H3-Image/examples/t2i.py
-
curl -L -o t2i.py https://huggingface.co/MiniMaxAI/MiniMax-H3-Image/resolve/main/examples/t2i.py
1.79 kB
| #!/usr/bin/env python3 | |
| """Send request.t2i.json to a MiniMax-H3-Image server and write the PNG. | |
| python3 t2i.py [--url http://127.0.0.1:30000] [--prompt FILE] [--size WxH] [--out t2i.png] | |
| --prompt and --size replace the prompt and the size in the request. | |
| Uses only the Python standard library. | |
| """ | |
| import argparse | |
| import base64 | |
| import json | |
| import urllib.request | |
| from pathlib import Path | |
| # absolute(), not resolve(): in the Hugging Face cache this file is a symlink into blobs/. | |
| HERE = Path(__file__).absolute().parent | |
| def main() -> None: | |
| parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) | |
| parser.add_argument("--url", default="http://127.0.0.1:30000", help="server base URL") | |
| parser.add_argument("--request", type=Path, default=HERE / "request.t2i.json", help="JSON request body") | |
| parser.add_argument("--prompt", type=Path, help="prompt file; replaces the prompt in the request") | |
| parser.add_argument("--size", help="WIDTHxHEIGHT; replaces the size in the request") | |
| parser.add_argument("--out", default="t2i.png") | |
| args = parser.parse_args() | |
| body = json.loads(args.request.read_text()) | |
| if args.prompt: | |
| body["prompt"] = args.prompt.read_text() | |
| if args.size: | |
| body["size"] = args.size | |
| request = urllib.request.Request( | |
| f"{args.url.rstrip('/')}/v1/images/generations", | |
| data=json.dumps(body).encode(), | |
| headers={"Content-Type": "application/json"}, | |
| ) | |
| with urllib.request.urlopen(request, timeout=1800) as response: | |
| payload = json.load(response) | |
| with open(args.out, "wb") as image: | |
| image.write(base64.b64decode(payload["data"][0]["b64_json"])) | |
| print(f"wrote {args.out}") | |
| if __name__ == "__main__": | |
| main() | |