Skip to content

shayari21/ControlNet-fastapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

223 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

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

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages