No description
Find a file
2026-01-03 14:51:59 -06:00
image_service init setup 2026-01-03 14:51:59 -06:00
.gitignore init setup 2026-01-03 14:51:59 -06:00
docker-compose.yml init setup 2026-01-03 14:51:59 -06:00
download_model.py init setup 2026-01-03 14:51:59 -06:00
generate_image.py init setup 2026-01-03 14:51:59 -06:00
generate_image_org.py init setup 2026-01-03 14:51:59 -06:00
README.md init setup 2026-01-03 14:51:59 -06:00

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:

  1. Docker
  2. Docker Compose (usually included with Docker Desktop)
  3. NVIDIA Container Toolkit for GPU support in Docker.

How to Run the Service

  1. Clone the repository (if you haven't already).

  2. Build and run the service using Docker Compose. From the root of the project directory, run:

    docker compose up --build
    

    The 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.

  3. 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 be 0.0 for 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.