GitHub - Penll/Fooocus-API2: FastAPI powered API for Fooocus

Fooocus-API

Docker Image CI

FastAPI powered API for Fooocus

Currently loaded Fooocus version: 2.1.781

Run with Replicate

Now you can use Fooocus-API by Replicate, the model is in konieshadow/fooocus-api.

With preset:

I believe this is the easiest way to generate image with Fooocus's power.

Reuse model files from Fooocus

You can simple copy user_path_config.txt file from your local Fooocus folder to Fooocus-API's root folder. See Customization for details.

Start app

Need python version >= 3.10, or use conda to create a new env.

conda env create -f environment.yaml
conda activate fooocus-api

Run

On default, server is listening on 'http://127.0.0.1:8888'

Using Foocus preset, run:

python main.py --preset anime

For pragram arguments, see

Start with docker

Before use docker with GPU, you should install NVIDIA Container Toolkit first.

Run

docker run --gpus=all -e NVIDIA_DRIVER_CAPABILITIES=compute,utility -e NVIDIA_VISIBLE_DEVICES=all -p 8888:8888 konieshadow/fooocus-api

For a more complex usage:

mkdir ~/repositories
mkdir -p ~/.cache/pip

docker run --gpus=all -e NVIDIA_DRIVER_CAPABILITIES=compute,utility -e NVIDIA_VISIBLE_DEVICES=all \
    -v ~/repositories:/app/repositories \
    -v ~/.cache/pip:/root/.cache/pip \
    -p 8888:8888 konieshadow/fooocus-api

It will persistent the dependent repositories and pip cache.

You can add -e PIP_INDEX_URL={pypi-mirror-url} to docker run command to change pip index url.

Test API

You can open the Swagger Document in "http://127.0.0.1:8888/docs", then click "Try it out" to send a request.

Completed Apis

Swagger openapi defination see openapi.json.

You can import it in Swagger-UI editor.

All the generation api support for response in PNG bytes directly when request's 'Accept' header is 'image/png'.

All the generation api support async process by pass parameter async_process to true. And then use query job api to retrieve progress and generation results.

Break change from v0.3.0:

  • The generation apis won't return base64 field expect request parameters set require_base64 to true.
  • The generation apis return a url field where the generated image can be requested via a static file url.

Text to Image

POST /v1/generation/text-to-image

Alternative api for the normal image generation of Fooocus Gradio interface.

Image Upscale or Variation

POST /v1/generation/image-upscale-vary

Alternative api for 'Upscale or Variation' tab of Fooocus Gradio interface.

Image Inpaint or Outpaint

POST /v1/generation/image-inpait-outpaint

Alternative api for 'Inpaint or Outpaint' tab of Fooocus Gradio interface.

Image Prompt

POST /v1/generation/image-prompt

Alternative api for 'Image Prompt' tab of Fooocus Gradio interface.

Query Job

GET /v1/generation/query-job

Query async generation request results, return job progress and generation results.

Query Job Queue Info

GET /v1/generation/job-queue

Query job queue info, include running job count, finished job count and last job id.

Get All Model Names

GET /v1/engines/all-models

Get all filenames of base model and lora.

Refresh Models

POST /v1/engines/refresh-models

Get All Fooocus Styles

GET /v1/engines/styles

Get all legal Fooocus styles.