FastAPI powered API for Fooocus
Currently loaded Fooocus version: 2.1.823
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.
You can simple copy config.txt
file from your local Fooocus folder to Fooocus-API's root folder. See Customization for details.
Need python version >= 3.10, or use conda to create a new env.
conda env create -f environment.yaml
conda activate fooocus-api
Run
python main.py
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
python main.py -h
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.
You can open the Swagger Document in "http://127.0.0.1:8888/docs", then click "Try it out" to send a request.
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.16:
- Parameter format for
loras
has changed for the img2img apis (the multipart/form-data requests). Now it requires JSON string.
Break change from v0.3.0:
- The generation apis won't return
base64
field expect request parameters setrequire_base64
to true. - The generation apis return a
url
field where the generated image can be requested via a static file url.
POST /v1/generation/text-to-image
Alternative api for the normal image generation of Fooocus Gradio interface.
POST /v1/generation/image-upscale-vary
Alternative api for 'Upscale or Variation' tab of Fooocus Gradio interface.
POST /v1/generation/image-inpait-outpaint
Alternative api for 'Inpaint or Outpaint' tab of Fooocus Gradio interface.
POST /v1/generation/image-prompt
Alternative api for 'Image Prompt' tab of Fooocus Gradio interface.
GET /v1/generation/query-job
Query async generation request results, return job progress and generation results.
You can get preview image of generation steps at current time by this api.
GET /v1/generation/job-queue
Query job queue info, include running job count, finished job count and last job id.
POST /v1/generation/stop
Stop current generation task.
GET /v1/engines/all-models
Get all filenames of base model and lora.
POST /v1/engines/refresh-models
GET /v1/engines/styles
Get all legal Fooocus styles.