[ English | 中文 ]
When upgrading from version 3.x to version 4.0, please read the following incompatibility notes:
- If you are using an external Fooocus model (that is, the model is not located in the
repositories
directory), delete therepositories
directory directly, and then update thegit pull
. - If not, move the
repositories
directory to any directory, delete therepositories
directory, then update thegit pull
, and move themodels
directory back to its original location when it is finished.
FastAPI powered API for Fooocus.
Currently loaded Fooocus version: 2.3.0.
This part from Fooocus project.
Fooocus is an image generating software (based on Gradio).
Fooocus is a rethinking of Stable Diffusion and Midjourney’s designs:
-
Learned from Stable Diffusion, the software is offline, open source, and free.
-
Learned from Midjourney, the manual tweaking is not needed, and users only need to focus on the prompts and images.
Fooocus has included and automated lots of inner optimizations and quality improvements. Users can forget all those difficult technical parameters, and just enjoy the interaction between human and computer to "explore new mediums of thought and expanding the imaginative powers of the human species"
I think you must have tried to use Gradio client to call Fooocus, which was a terrible experience for me.
Fooocus API uses FastAPI provides the REST
API for using Fooocus. Now, you can use Fooocus's powerful ability in any language you like.
In addition, we also provide detailed documentation and sample code
Now you can use Fooocus-API by Replicate, the model is on konieshadow/fooocus-api.
With preset:
I believe this is the easiest way to generate image with Fooocus's power.
You need python version >= 3.10, or use conda to create a new env.
The hardware requirements are what Fooocus needs. You can find detail here
You can easily start app follow this step use conda:
conda env create -f environment.yaml
conda activate fooocus-api
and then, run python main.py
to start app, default, server is listening on http://127.0.0.1:8888
If you are running the project for the first time, you may have to wait for a while, during which time the program will complete the rest of the installation and download the necessary models. You can also do these steps manually, which I'll mention later.
Similar to using conda, create a virtual environment, and then start and wait for a while
# windows
python -m venv venv
.\venv\Scripts\Activate
# linux
python -m venv venv
source venv/bin/activate
and then, run python main.py
If you want to deal with environmental problems manually and download the model in advance, you can refer to the following steps
After creating a complete environment using conda or venv, you can manually complete the installation of the subsequent environment, just follow
first, install requirements: pip install -r requirements.txt
then, pytorch with cuda: pip install torch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0 --index-url https://download.pytorch.org/whl/cu121
, you can find more info about this here,
It is important to note that for pytorch and cuda versions, the recommended version of Fooocus is used, which is currently pytorch2.1.0+cuda12.1. If you insist, you can also use other versions, but you need to add
--skip-pip
when you start app, otherwise the recommended version will be installed automatically
Go to the repositories
directories, download models and put it into repositories\Fooocus\models
If you have Fooocus installed, see already-exist-fooocus
here is a list need to download for startup (for different startup params maybe difference):
-
checkpoint: path to
repositories\Fooocus\models\checkpoints
-
vae_approx: path to
repositories\Fooocus\models\vae_approx
-
lora: path to
repositories\Fooocus\models\loras
I've uploaded the model I'm using, which contains almost all the base models that Fooocus will use! I put it here 提取码:
D4Mk
If you already have Fooocus installed, and it is work well, The recommended way is to reuse models, you just simple copy config.txt
file from your local Fooocus folder to Fooocus-API root folder. See Customization for details.
Use this method you will have both Fooocus and Fooocus-API running at the same time. And they operate independently and do not interfere with each other.
Do not copy Fooocus to repositories directory
Before use docker with GPU, you should install NVIDIA Container Toolkit first.
Run
docker run -d --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 -d --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 be 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.
From version 0.4.0.0, Full environment include in docker image, mapping
models
or project root if you needed For example:docker run -d --gpus all \ -v /Fooocus-API:/app \ -p 8888:8888 konieshadow/fooocus-api
-h, --help
show this help message and exit--port PORT
Set the listen port, default: 8888--host HOST
Set the listen host, default: 127.0.0.1--base-url BASE_URL
Set base url for outside visit, default is http://host:port--log-level LOG_LEVEL
Log info for Uvicorn, default: info--skip-pip
Skip automatic pip install when setup--preload-pipeline
Preload pipeline before start http server--queue-size QUEUE_SIZE
Working queue size, default: 100, generation requests exceeding working queue size will return failure--queue-history QUEUE_HISTORY
Finished jobs reserve size, tasks exceeding the limit will be deleted, including output image files, default: 0, means no limit--webhook-url WEBHOOK_URL
Webhook url for notify generation result, default: None--persistent
Store history to db--apikey APIKEY
Set apikey to enable secure api, default: None
Since v0.3.25, added CMD flags support of Fooocus. You can pass any argument which Fooocus supported.
For example, to startup image generation (need more vRAM):
python main.py --all-in-fp16 --always-gpu
For Fooocus CMD flags, see here.
[24/01/31] v0.3.30 : Add secure API future, use --apikey APIKEY
to set apikey at startup
[24/01/26] v0.3.30 : Optimize the underlying logic of task execution, default queue size to 100
[24/01/10] v0.3.29 : support for store history to db
[24/01/09] v0.3.29 : Image Prompt Mixing requirements implemented, With this implementation, you can send image prompts, and perform inpainting or upscale with a single request.
[24/01/04] v0.3.29 : Merged Fooocus v2.1.860
[24/01/03] v0.3.28 : add text-to-image-with-ip interface
[23/12/29] v0.3.27 : Add describe interface,now you can get prompt from image
[23/12/29] v0.3.27 : Add query job history api. Add webhook_url support for each generation request.
[23/12/28] v0.3.26 : Break Change: Add web-hook cmd flag for notify generation result. Change async job id to uuid to avoid conflict between each startup.
[23/12/22] v0.3.25 : Add CMD flags support of Fooocus. Break Change: Removed cli argument disable-private-log
. You can use Fooocus's --disable-image-log
for the same purpose.
older change history you can find in release page
you can find all api detail here
This repository is licensed under the GUN General Public License v3.0
The default checkpoint is published by RunDiffusion, is licensed under the CreativeML Open RAIL-M.
or, you can find it here
Thanks for all your contributions and efforts towards improving the Fooocus API. We thank you for being part of our ✨ community ✨!