Skip to content

A FastAPI-based backend for generating images using ControlNet, enabling edge detection-based image generation with AI.

License

Notifications You must be signed in to change notification settings

shayari21/ControlNet-fastapi

Repository files navigation

ControlNet-FastAPI 🚀

A FastAPI-based backend for generating images using ControlNet, enabling edge detection-based image generation with AI.

Table of Contents


Overview

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.


Features

  • 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.

Installation

1. Clone the Repository

git clone https://github.com/shayari21/ControlNet-fastapi.git
cd ControlNet-fastapi

2. Setting up environment and dependecies

Using environmemt-fastapi.yaml(This is the enhanced version of the original environment.yaml):

conda env create -f environment_fastapi.yaml
conda activate controlNet

3. Run the FastAPI Server

cd app
uvicorn main:app --host 0.0.0.0 --port 8000

4. Usage

Once the server is running, open http://127.0.0.1:8000/docs in your browser to access the interactive API documentation.

image

image

Docker Support

1. Build Docker Image (From ControlNet-fastapi main directory)

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 .

image

2. Run Container

docker run -gpus all -p 8000:8000 controlnet-fastapi

image

3. Test API

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. image

image


📖 References

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

About

A FastAPI-based backend for generating images using ControlNet, enabling edge detection-based image generation with AI.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages