A FastAPI-based backend for generating images using ControlNet, enabling edge detection-based image generation with AI.
This project integrates ControlNet with FastAPI, allowing users to generate AI-driven images using edge detection. The API processes input images and generates corresponding output images based on the ControlNet model.
- ✅ FastAPI-based backend for handling input requests in the form of images and prompts.
- ✅ Integration with ControlNet for image generation using Denoising Diffusion Implicit Models (DDIM).
- ✅ Uses Conda environment for efficient dependency management.
- ✅ Supports all applications originally supported by ControlNet.
- ✅ Dockerized for easy deployment.
git clone https://github.com/shayari21/ControlNet-fastapi.git
cd ControlNet-fastapi
Using environmemt-fastapi.yaml(This is the enhanced version of the original environment.yaml):
conda env create -f environment_fastapi.yaml
conda activate controlNet
cd app
uvicorn main:app --host 0.0.0.0 --port 8000
Once the server is running, open http://127.0.0.1:8000/docs
in your browser to access the interactive API documentation.
Run the Dockerfile
in ControlNet-fastapi\
directory. The Dockerfile
creates a conda environment inside the docker image using environment_fastapi.yaml
.
cd ..
docker build -t controlnet-fastapi .
docker run -gpus all -p 8000:8000 controlnet-fastapi
curl -X 'POST' \
'http://127.0.0.1:8000/generate_image/' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F '[email protected];type=image/png' \
-F 'prompt=bird'
or open http://127.0.0.1:8000/docs
in your browser to access the interactive API documentation similar to local usage.
Here are some useful references related to ControlNet and FastAPI:
🔗 ControlNet Repository
🔗 ControlNet Paper: Adding Conditional Control to Text-to-Image Diffusion Models
🔗 FastAPI Documentation: FastAPI Official Docs
🔗 Uvicorn ASGI Server: Uvicorn GitHub
🔗 Docker Documentation: Docker Docs