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-fastapiUsing 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 8000Once 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-fastapicurl -X 'POST' \
'http://127.0.0.1:8000/generate_image/' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F 'file=@bird.png;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




