A Python-based application for generating images with Stable Diffusion models. This project includes a Flask-based server that manages the model loading and image generation, and a Gradio-based client interface for easy interaction.
- Model Detection: Automatically detects and catalogs Stable Diffusion models in specified directories
- Client Interface: User-friendly Gradio web interface for prompt input and image generation
- Server Backend: Flask server that handles model loading and image generation requests
- Support for Multiple Models: Ability to switch between different Stable Diffusion models
- Customizable Generation Parameters: Control over width, height, steps, guidance scale, and scheduler
- Optimized for GPU: Uses CUDA when available for faster generation
The application consists of three main Python files:
- server.py: Flask server that loads models and handles image generation
- client.py: Gradio-based user interface for generating images
- model_detection.py: Utility for detecting and cataloging Stable Diffusion models
- Python 3.7+
- PyTorch with CUDA (for GPU acceleration)
- diffusers
- transformers
- Flask
- Gradio
- PIL
- Clone this repository
- Install required dependencies:
pip install torch diffusers transformers flask gradio pillow - Ensure your Stable Diffusion models are organized in appropriate directories
- Update the
MODEL_BASE_DIRin server.py to point to your models directory - Run the server:
python server.py - Run the client:
python client.py
- Start the server and client
- Connect the client to the server (default: http://localhost:8001)
- Select a model from the dropdown
- Enter a prompt describing the image you want to generate
- Optional: Add a negative prompt to specify what to avoid
- Adjust generation parameters as needed
- Click "Generate Image" button
- The generated image will appear and be saved in the output directory
The application looks for models in the following directories:
- Stable-diffusion, SD, stable-diffusion (for standard SD models)
- SDXL, SD-XL, stable-diffusion-xl (for SDXL models)
Models should be in .safetensors, .ckpt, or .pt format.
MIT
This application uses Hugging Face's diffusers library and Stable Diffusion models.