AI Image Studio is a web application that leverages Stable Diffusion with ControlNet to generate images based on user-uploaded images and prompts. The project combines a FastAPI backend with a React frontend, orchestrated using Docker and RabbitMQ for asynchronous task processing. It supports multiple preprocessors (Canny Edge, Pose, and Depth) to guide image generation.
- Image Generation: Generate images using Stable Diffusion with ControlNet models (Canny, Pose, Depth).
- Asynchronous Processing: Tasks are queued and processed using RabbitMQ for efficient handling.
- Database Integration: PostgreSQL stores generation metadata with SQLAlchemy ORM.
- Modern Frontend: Built with React, featuring a responsive UI with Tailwind CSS styling.
- Dockerized Backend: Run the entire backend (API, worker, database, RabbitMQ) with Docker Compose.
- Real-time Status Updates: Poll generation status and display results dynamically.
- Generation History: View past generations with details like prompts and preprocessors.
- Backend: FastAPI, Python 3.10, SQLAlchemy, asyncpg, aio-pika
- Frontend: React, TypeScript, react-query, zustand, Tailwind CSS
- Queue: RabbitMQ for task queuing
- Database: PostgreSQL for persistent storage
- Containerization: Docker with NVIDIA CUDA support for GPU acceleration
- AI/ML: Stable Diffusion, ControlNet (Canny, OpenPose, Depth), easy_dwpose, PyTorch
Ensure you have the following installed:
- π³ Docker (for backend)
- π³ Docker Compose
- π’ Node.js (v18 or later, for frontend)
- π’ npm (for frontend)
- π₯οΈ NVIDIA GPU with CUDA support (optional, for faster image generation)
-
Clone the Repository
git clone https://github.com/amir2628/ai-image-studio.git cd ai-image-studio -
Set Up Environment
Ensure you have a
requirements.txtfile with all dependencies listed. TheDockerfilehandles installing these dependencies. -
Run Docker Compose
Start the backend services (FastAPI, RabbitMQ, PostgreSQL, and worker) using Docker Compose:
docker-compose up -d --build
This will:
- Build the FastAPI and worker images.
- Start PostgreSQL (
postgres:15). - Start RabbitMQ (
rabbitmq:3-management). - Run the FastAPI server on
http://localhost:8000. - Run the worker for processing image generation tasks.
-
Verify Services
- FastAPI: Visit
http://localhost:8000/docsfor the API documentation. - RabbitMQ Management: Access
http://localhost:15672(default credentials:guest/guest). - PostgreSQL: Connect to
localhost:5432withpostgres/postgrescredentials.
- FastAPI: Visit
-
Stop Services
docker-compose down
-
Navigate to the Frontend Directory
Ensure you are in the directory containing the React frontend (where
package.jsonis located). -
Install Dependencies
npm install
-
Run the Development Server
npm run dev
The frontend will be available at
http://localhost:5173.
-
Open the Application
- Access the frontend at
http://localhost:5173. - The backend API is available at
http://localhost:8000.
- Access the frontend at
-
Generate an Image
- Upload an image using the drag-and-drop interface.
- Select a preprocessor (Canny, Pose, or Depth).
- Enter a prompt describing the desired output.
- Click "Generate Image" to queue the task.
-
Monitor Progress
- The frontend polls the backend for generation status.
- View the result once the status changes to "completed" or check for errors.
-
View History
- Navigate to the "History" page via the sidebar to see past generations.
- Each entry includes the prompt, preprocessor, status, and result (if completed).
The backend is orchestrated using Docker Compose with the following services:
- postgres: PostgreSQL database for storing generation metadata.
- rabbitmq: RabbitMQ for task queuing and management.
- api: FastAPI server handling HTTP requests and task queuing.
- worker: Background worker processing image generation tasks with GPU support.
The Dockerfile uses nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04 as the base image, ensuring GPU compatibility for Stable Diffusion tasks.
-
Backend:
- Database URL:
postgresql+asyncpg://postgres:postgres@postgres/sd_controlnet - RabbitMQ:
amqp://guest:guest@rabbitmq/ - API Port:
8000 - Static File Mounts:
/uploadsand/generations
- Database URL:
-
Frontend:
- API Base URL:
http://localhost:8000 - CORS: Configured to allow
http://localhost:5173
- API Base URL:
-
Docker Issues:
- Ensure Docker and Docker Compose are installed and running.
- Check container logs:
docker-compose logs. - Verify NVIDIA GPU drivers if using CUDA.
-
Backend Errors:
- Check RabbitMQ connection: Ensure
rabbitmqservice is healthy (http://localhost:15672). - Verify PostgreSQL is running: Use
pg_isready -U postgres -h localhost.
- Check RabbitMQ connection: Ensure
-
Frontend Errors:
- Ensure the backend API is running before starting the frontend.
- Check browser console for CORS or network errors.
-
GPU Memory:
- Monitor GPU memory usage in
worker.pylogs. - Adjust
deploy.resources.limits.memoryindocker-compose.ymlif needed.
- Monitor GPU memory usage in
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please:
- Fork the repository.
- Create a feature branch (
git checkout -b feature/YourFeature). - Commit your changes (
git commit -m 'Add YourFeature'). - Push to the branch (
git push origin feature/YourFeature). - Open a pull request.
For questions or feedback, reach out to Amir or open an issue on GitHub.
β If you find this project useful, please give it a star on GitHub!