| image_service | ||
| .gitignore | ||
| docker-compose.yml | ||
| download_model.py | ||
| generate_image.py | ||
| generate_image_org.py | ||
| README.md | ||
Z-Image Service
A lightweight, Dockerized FastAPI service for high-performance text-to-image generation using the Z-Image-Turbo model.
Features
- FastAPI Backend: Exposes the image generation model via a simple and robust REST API.
- Dockerized: Easy to set up and run with Docker and Docker Compose, ensuring a consistent environment.
- GPU Accelerated: Utilizes NVIDIA GPUs via the NVIDIA Container Toolkit for fast inference.
- Memory Efficient: Uses CPU offloading to fit large models onto consumer-grade GPUs.
- Scalable: Designed as a microservice, making it easy to integrate into larger applications.
Prerequisites
Before you begin, ensure you have the following installed:
- Docker
- Docker Compose (usually included with Docker Desktop)
- NVIDIA Container Toolkit for GPU support in Docker.
How to Run the Service
-
Clone the repository (if you haven't already).
-
Build and run the service using Docker Compose. From the root of the project directory, run:
docker compose up --buildThe first time you run this, it will download the base Docker image, Python packages, and the machine learning model, which may take some time. Subsequent launches will be much faster.
-
The API will be running and available at
http://localhost:8000.
API Usage
You can interact with the service by sending POST requests to the /generate endpoint.
Request Body
The endpoint accepts a JSON body with the following parameters:
prompt(str, required): The text prompt to generate an image from.height(int, optional, default: 1024): The height of the output image.width(int, optional, default: 1024): The width of the output image.num_inference_steps(int, optional, default: 9): The number of inference steps.guidance_scale(float, optional, default: 0.0): The guidance scale. Must be0.0for this Turbo model.seed(int, optional, default: 42): The random seed for generation.
Example
Here is an example using curl to generate an image and save it to a file:
curl -X POST http://localhost:8000/generate \
-H "Content-Type: application/json" \
-d '{"prompt": "A photorealistic image of a futuristic mechanical keyboard on a wooden desk"}' \
--output generated_image.png
If successful, the generated image will be saved as generated_image.png in your current directory.