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/edit.py from MiniMaxAI/MiniMax-H3-Image: direct link, hf CLI and curl.
- Browser
- Download file 2.79 kB
-
https://huggingface.co/MiniMaxAI/MiniMax-H3-Image/resolve/refs%2Fpr%2F1/examples/edit.py
- Command line
-
hf download hf://MiniMaxAI/MiniMax-H3-Image@refs/pr/1/examples/edit.py
-
curl -L -o edit.py https://huggingface.co/MiniMaxAI/MiniMax-H3-Image/resolve/refs%2Fpr%2F1/examples/edit.py
2.79 kB
| #!/usr/bin/env python3 | |
| """Send reference1.png and prompt.edit.txt to a MiniMax-H3-Image server and write the PNG. | |
| python3 edit.py [--url http://127.0.0.1:30000] [--out edit.png] | |
| The images are sent in --image order, which defines <Picture 1>, <Picture 2>, ... in the | |
| prompt. Uses only the Python standard library. | |
| """ | |
| import argparse | |
| import base64 | |
| import json | |
| import mimetypes | |
| import urllib.request | |
| import uuid | |
| 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 multipart(fields: dict, images: list) -> tuple: | |
| boundary = f"minimax-h3-image-{uuid.uuid4().hex}" | |
| parts = [] | |
| for name, value in fields.items(): | |
| parts.append(f'--{boundary}\r\nContent-Disposition: form-data; name="{name}"\r\n\r\n{value}\r\n'.encode()) | |
| for path in images: | |
| content_type = mimetypes.guess_type(path.name)[0] or "application/octet-stream" | |
| parts.append( | |
| f'--{boundary}\r\nContent-Disposition: form-data; name="image"; filename="{path.name}"\r\n' | |
| f"Content-Type: {content_type}\r\n\r\n".encode() | |
| ) | |
| parts.append(path.read_bytes() + b"\r\n") | |
| parts.append(f"--{boundary}--\r\n".encode()) | |
| return b"".join(parts), f"multipart/form-data; boundary={boundary}" | |
| 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("--image", action="append", type=Path, | |
| help="reference image; repeat for <Picture 2>, ... (default: reference1.png)") | |
| parser.add_argument("--prompt", type=Path, default=HERE / "prompt.edit.txt", help="prompt file") | |
| parser.add_argument("--size", default="4096x4096", help="WIDTHxHEIGHT") | |
| parser.add_argument("--seed", type=int, default=1234) | |
| parser.add_argument("--out", default="edit.png") | |
| args = parser.parse_args() | |
| fields = { | |
| "prompt": args.prompt.read_text(), | |
| "size": args.size, | |
| "seed": str(args.seed), | |
| "generator_device": "cpu", | |
| "response_format": "b64_json", | |
| "output_format": "png", | |
| } | |
| body, content_type = multipart(fields, args.image or [HERE / "reference1.png"]) | |
| request = urllib.request.Request( | |
| f"{args.url.rstrip('/')}/v1/images/edits", data=body, headers={"Content-Type": content_type} | |
| ) | |
| 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() | |