Skip to content
This repository was archived by the owner on Aug 24, 2025. It is now read-only.

mvfolino68/python-fastapi-stabile-diffusion-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python FastAPI backend for Stable Diffusion

Example of an API for Stable Diffusion inference using FastAPI and Hugging Face.

Documentation

Installing

  1. Clone the repository locally

    git clone git@github.com:mvfolino68/python-fastapi-stabile-diffusion-backend.git
  2. Create a virtual environment for Python and activate it. Install requirements

    python3 venv -m api
    source api/bin/activate
    pip install -r requirements.txt
  3. create .env file using the .env.example provided.

    1. Create an API key from Hugging Face. More information
      1. paste the API key into the environment file.
    2. Sign up for a free MongoDB account, create a cluster, database and collection. More information
      1. paste the connection values into the environment file.
  4. Start the API

    uvicorn image.main:app --reload --lifespan=on --use-colors --loop uvloop --http httptools
  5. Make Test API Request

    You will see a url displayed in your terminal. Navigate to http://127.0.0.1:8000/docs to try the API.

  6. Make a request to the API

    curl --location --request POST 'http://localhost:8000/api/v1/image-generator' \
    --header 'Content-Type: application/json' \
    --data-raw '{
    "prompt": "this is a sample image prompt",
    "num_inference_steps": 0,
    "negative_prompt": "this is a sample for a negative image prompt."
    }'

Image prompt help

Dockerfile

Working on mounting a volume to avoud having to download the model with each build or new image. Will need to update the model_id in the repository.py file when testings. Currently the container stops when using mounted volume for model.

without docker the local model works fine.

Create a docker image with docker build -t fastapi-example . Run the docker image with docker run -v $(pwd)/models:/app/models -d -p 8000:8000 fastapi-example

Tutorials

todo

API Reference

todo

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published