A modern web interface for Stable Diffusion 3 text-to-image generation, built with Next.js and FastAPI.
.
├── . # Next.js frontend
├── model-server/ # FastAPI and TorchServe backend
│ ├── server.py # FastAPI server
│ ├── config.properties
│ └── sd3_handler.py # TorchServe handler
└── README.md
cd sd3-ui
npm install
npm run dev
The UI will be available at http://localhost:3000
First, download the Stable Diffusion 3 model:
cd model-server
#!/usr/bin/env python3
from diffusers import StableDiffusion3Pipeline
import torch
pipe = StableDiffusion3Pipeline.from_pretrained(
"stabilityai/stable-diffusion-3-medium-diffusers",
torch_dtype=torch.bfloat16
)
pipe.save_pretrained("./sd3-model")
Then zip the model artifacts:
cd sd3-model
zip -0 -r ../sd3-model.zip *
Start a TorchServe container:
docker run -it --rm --shm-size=1g \
--ulimit memlock=-1 \
--ulimit stack=67108864 \
--gpus all \
-v `pwd`:/opt/src \
pytorch/torchserve:0.12.0-gpu bash
Create the model archive:
cd /opt/src
torch-model-archiver --model-name sd3 \
--version 1.0 \
--handler sd3_handler.py \
--extra-files sd3-model.zip \
-r requirements.txt \
--archive-format zip-store
docker run --rm --shm-size=1g \
--ulimit memlock=-1 \
--ulimit stack=67108864 \
-p8080:8080 \
-p8081:8081 \
-p8082:8082 \
-p7070:7070 \
-p7071:7071 \
--gpus all \
-v /path/to/config.properties:/home/model-server/config.properties \
--mount type=bind,source=/path/to/models,target=/tmp/models \
pytorch/torchserve:0.12.0-gpu \
torchserve --model-store=/tmp/models
Install requirements:
pip install -r requirements-server.txt
Start the server:
cd model-server
python server.py
The FastAPI server will be available at http://localhost:9080
- 🎨 Modern, responsive UI with dark mode
- 🖼️ Real-time generation progress
- 💾 Local storage for generated images
- ⬇️ Download generated images
- 🗑️ Delete unwanted generations
- ⏱️ Generation time tracking
Create a .env.local
file in the sd3-ui directory:
BACKEND_URL=http://localhost:9080
POST /text-to-image
: Generate image from text promptGET /results/{job_id}
: Get generation resultsGET /health
: Health check endpoint
- Node.js 22
- npm or yarn
- Python 3.11+
- CUDA-compatible GPU
- Docker
- See
requirements-server.txt
for Python packages
The frontend uses Next.js 15 with App Router and is styled using Tailwind CSS and shadcn/ui components. The backend uses FastAPI for the API server and TorchServe for model serving.
MIT
Contributions are welcome! Please feel free to submit a Pull Request.