Arivmta19 commited on
Commit
2eb6440
1 Parent(s): 0c3bce1

Upload folder using huggingface_hub

Browse files
.github/workflows/update_space.yml ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Run Python script
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ build:
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - name: Checkout
14
+ uses: actions/checkout@v2
15
+
16
+ - name: Set up Python
17
+ uses: actions/setup-python@v2
18
+ with:
19
+ python-version: '3.9'
20
+
21
+ - name: Install Gradio
22
+ run: python -m pip install gradio
23
+
24
+ - name: Log in to Hugging Face
25
+ run: python -c 'import huggingface_hub; huggingface_hub.login(token="${{ secrets.hf_token }}")'
26
+
27
+ - name: Deploy to Spaces
28
+ run: gradio deploy
Dockerfile CHANGED
@@ -3,7 +3,7 @@ ENV DEBIAN_FRONTEND noninteractive
3
  ENV CMDARGS --listen
4
 
5
  RUN apt-get update -y && \
6
- apt-get install -y curl libgl1 libglib2.0-0 python3-pip python-is-python3 git && \
7
  apt-get clean && \
8
  rm -rf /var/lib/apt/lists/*
9
 
 
3
  ENV CMDARGS --listen
4
 
5
  RUN apt-get update -y && \
6
+ apt-get install -y curl libgl1 libglib2.0-0 libgl1-mesa-glx python3-pip python-is-python3 git && \
7
  apt-get clean && \
8
  rm -rf /var/lib/apt/lists/*
9
 
README.md CHANGED
@@ -1,10 +1,6 @@
1
  ---
2
- title: Img2img
3
- emoji: 👀
4
- colorFrom: gray
5
- colorTo: red
6
  sdk: gradio
7
- sdk_version: 4.21.0
8
- app_file: app.py
9
- pinned: false
10
- ---
 
1
  ---
2
+ title: img2img
3
+ app_file: webui.py
 
 
4
  sdk: gradio
5
+ sdk_version: 3.41.2
6
+ ---
 
 
docker.md CHANGED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Fooocus on Docker
2
+
3
+ The docker image is based on NVIDIA CUDA 12.3 and PyTorch 2.0, see [Dockerfile](Dockerfile) and [requirements_docker.txt](requirements_docker.txt) for details.
4
+
5
+ ## Quick start
6
+
7
+ **This is just an easy way for testing. Please find more information in the [notes](#notes).**
8
+
9
+ 1. Clone this repository
10
+ 2. Build the image with `docker compose build`
11
+ 3. Run the docker container with `docker compose up`. Building the image takes some time.
12
+
13
+ When you see the message `Use the app with http://0.0.0.0:7865/` in the console, you can access the URL in your browser.
14
+
15
+ Your models and outputs are stored in the `fooocus-data` volume, which, depending on OS, is stored in `/var/lib/docker/volumes`.
16
+
17
+ ## Details
18
+
19
+ ### Update the container manually
20
+
21
+ When you are using `docker compose up` continuously, the container is not updated to the latest version of Fooocus automatically.
22
+ Run `git pull` before executing `docker compose build --no-cache` to build an image with the latest Fooocus version.
23
+ You can then start it with `docker compose up`
24
+
25
+ ### Import models, outputs
26
+ If you want to import files from models or the outputs folder, you can uncomment the following settings in the [docker-compose.yml](docker-compose.yml):
27
+ ```
28
+ #- ./models:/import/models # Once you import files, you don't need to mount again.
29
+ #- ./outputs:/import/outputs # Once you import files, you don't need to mount again.
30
+ ```
31
+ After running `docker compose up`, your files will be copied into `/content/data/models` and `/content/data/outputs`
32
+ Since `/content/data` is a persistent volume folder, your files will be persisted even when you re-run `docker compose up --build` without above volume settings.
33
+
34
+
35
+ ### Paths inside the container
36
+
37
+ |Path|Details|
38
+ |-|-|
39
+ |/content/app|The application stored folder|
40
+ |/content/app/models.org|Original 'models' folder.<br> Files are copied to the '/content/app/models' which is symlinked to '/content/data/models' every time the container boots. (Existing files will not be overwritten.) |
41
+ |/content/data|Persistent volume mount point|
42
+ |/content/data/models|The folder is symlinked to '/content/app/models'|
43
+ |/content/data/outputs|The folder is symlinked to '/content/app/outputs'|
44
+
45
+ ### Environments
46
+
47
+ You can change `config.txt` parameters by using environment variables.
48
+ **The priority of using the environments is higher than the values defined in `config.txt`, and they will be saved to the `config_modification_tutorial.txt`**
49
+
50
+ Docker specified environments are there. They are used by 'entrypoint.sh'
51
+ |Environment|Details|
52
+ |-|-|
53
+ |DATADIR|'/content/data' location.|
54
+ |CMDARGS|Arguments for [entry_with_update.py](entry_with_update.py) which is called by [entrypoint.sh](entrypoint.sh)|
55
+ |config_path|'config.txt' location|
56
+ |config_example_path|'config_modification_tutorial.txt' location|
57
+
58
+ You can also use the same json key names and values explained in the 'config_modification_tutorial.txt' as the environments.
59
+ See examples in the [docker-compose.yml](docker-compose.yml)
60
+
61
+ ## Notes
62
+
63
+ - Please keep 'path_outputs' under '/content/app'. Otherwise, you may get an error when you open the history log.
64
+ - Docker on Mac/Windows still has issues in the form of slow volume access when you use "bind mount" volumes. Please refer to [this article](https://docs.docker.com/storage/volumes/#use-a-volume-with-docker-compose) for not using "bind mount".
65
+ - The MPS backend (Metal Performance Shaders, Apple Silicon M1/M2/etc.) is not yet supported in Docker, see https://github.com/pytorch/pytorch/issues/81224
66
+ - You can also use `docker compose up -d` to start the container detached and connect to the logs with `docker compose logs -f`. This way you can also close the terminal and keep the container running.
entry_with_update.py CHANGED
@@ -44,3 +44,17 @@ except Exception as e:
44
 
45
  print('Update succeeded.')
46
  from launch import *
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
  print('Update succeeded.')
46
  from launch import *
47
+
48
+
49
+ iface = gr.Interface(
50
+ fn=your_function_name, # Replace your_function_name with the function you want to run
51
+ title='Your Title',
52
+ description='Your Description',
53
+ inputs=[], # Add your input components here
54
+ outputs=[], # Add your output components here
55
+ theme='default', # Change if you want a different theme
56
+ allow_flagging=False # Change if you want to allow flagging
57
+ )
58
+
59
+ # Launch the Gradio interface
60
+ iface.launch()
launch.py CHANGED
@@ -32,7 +32,7 @@ def prepare_environment():
32
  torch_index_url = os.environ.get('TORCH_INDEX_URL', "https://download.pytorch.org/whl/cu121")
33
  torch_command = os.environ.get('TORCH_COMMAND',
34
  f"pip install torch==2.1.0 torchvision==0.16.0 --extra-index-url {torch_index_url}")
35
- requirements_file = os.environ.get('REQS_FILE', "requirements.txt")
36
 
37
  print(f"Python {sys.version}")
38
  print(f"Fooocus version: {fooocus_version.version}")
 
32
  torch_index_url = os.environ.get('TORCH_INDEX_URL', "https://download.pytorch.org/whl/cu121")
33
  torch_command = os.environ.get('TORCH_COMMAND',
34
  f"pip install torch==2.1.0 torchvision==0.16.0 --extra-index-url {torch_index_url}")
35
+ requirements_file = os.environ.get('REQS_FILE', "requirements_versions.txt")
36
 
37
  print(f"Python {sys.version}")
38
  print(f"Fooocus version: {fooocus_version.version}")
oryx-build-commands.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ PlatformWithVersion=Python
2
+ BuildCommands=conda env create --file environment.yml --prefix ./venv --quiet
readme.md ADDED
@@ -0,0 +1,446 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: img2img
3
+ app_file: webui.py
4
+ sdk: gradio
5
+ sdk_version: 3.41.2
6
+ ---
7
+
8
+
9
+ <div align=center>
10
+ <img src="https://github.com/lllyasviel/Fooocus/assets/19834515/483fb86d-c9a2-4c20-997c-46dafc124f25">
11
+
12
+ **Non-cherry-picked** random batch by just typing two words "forest elf",
13
+
14
+ without any parameter tweaking, without any strange prompt tags.
15
+
16
+ See also **non-cherry-picked** generalization and diversity tests [here](https://github.com/lllyasviel/Fooocus/discussions/2067) and [here](https://github.com/lllyasviel/Fooocus/discussions/808) and [here](https://github.com/lllyasviel/Fooocus/discussions/679) and [here](https://github.com/lllyasviel/Fooocus/discussions/679#realistic).
17
+
18
+ In the entire open source community, only Fooocus can achieve this level of **non-cherry-picked** quality.
19
+
20
+ </div>
21
+
22
+
23
+ # Fooocus
24
+
25
+ Fooocus is an image generating software (based on [Gradio](https://www.gradio.app/)).
26
+
27
+ Fooocus is a rethinking of Stable Diffusion and Midjourney’s designs:
28
+
29
+ * Learned from Stable Diffusion, the software is offline, open source, and free.
30
+
31
+ * Learned from Midjourney, the manual tweaking is not needed, and users only need to focus on the prompts and images.
32
+
33
+ Fooocus has included and automated [lots of inner optimizations and quality improvements](#tech_list). 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" `[1]`.
34
+
35
+ Fooocus has simplified the installation. Between pressing "download" and generating the first image, the number of needed mouse clicks is strictly limited to less than 3. Minimal GPU memory requirement is 4GB (Nvidia).
36
+
37
+ `[1]` David Holz, 2019.
38
+
39
+ **Recently many fake websites exist on Google when you search “fooocus”. Do not trust those – here is the only official source of Fooocus.**
40
+
41
+ ## [Installing Fooocus](#download)
42
+
43
+ # Moving from Midjourney to Fooocus
44
+
45
+ Using Fooocus is as easy as (probably easier than) Midjourney – but this does not mean we lack functionality. Below are the details.
46
+
47
+ | Midjourney | Fooocus |
48
+ | - | - |
49
+ | High-quality text-to-image without needing much prompt engineering or parameter tuning. <br> (Unknown method) | High-quality text-to-image without needing much prompt engineering or parameter tuning. <br> (Fooocus has an offline GPT-2 based prompt processing engine and lots of sampling improvements so that results are always beautiful, no matter if your prompt is as short as “house in garden” or as long as 1000 words) |
50
+ | V1 V2 V3 V4 | Input Image -> Upscale or Variation -> Vary (Subtle) / Vary (Strong)|
51
+ | U1 U2 U3 U4 | Input Image -> Upscale or Variation -> Upscale (1.5x) / Upscale (2x) |
52
+ | Inpaint / Up / Down / Left / Right (Pan) | Input Image -> Inpaint or Outpaint -> Inpaint / Up / Down / Left / Right <br> (Fooocus uses its own inpaint algorithm and inpaint models so that results are more satisfying than all other software that uses standard SDXL inpaint method/model) |
53
+ | Image Prompt | Input Image -> Image Prompt <br> (Fooocus uses its own image prompt algorithm so that result quality and prompt understanding are more satisfying than all other software that uses standard SDXL methods like standard IP-Adapters or Revisions) |
54
+ | --style | Advanced -> Style |
55
+ | --stylize | Advanced -> Advanced -> Guidance |
56
+ | --niji | [Multiple launchers: "run.bat", "run_anime.bat", and "run_realistic.bat".](https://github.com/lllyasviel/Fooocus/discussions/679) <br> Fooocus support SDXL models on Civitai <br> (You can google search “Civitai” if you do not know about it) |
57
+ | --quality | Advanced -> Quality |
58
+ | --repeat | Advanced -> Image Number |
59
+ | Multi Prompts (::) | Just use multiple lines of prompts |
60
+ | Prompt Weights | You can use " I am (happy:1.5)". <br> Fooocus uses A1111's reweighting algorithm so that results are better than ComfyUI if users directly copy prompts from Civitai. (Because if prompts are written in ComfyUI's reweighting, users are less likely to copy prompt texts as they prefer dragging files) <br> To use embedding, you can use "(embedding:file_name:1.1)" |
61
+ | --no | Advanced -> Negative Prompt |
62
+ | --ar | Advanced -> Aspect Ratios |
63
+ | InsightFace | Input Image -> Image Prompt -> Advanced -> FaceSwap |
64
+ | Describe | Input Image -> Describe |
65
+
66
+ We also have a few things borrowed from the best parts of LeonardoAI:
67
+
68
+ | LeonardoAI | Fooocus |
69
+ | - | - |
70
+ | Prompt Magic | Advanced -> Style -> Fooocus V2 |
71
+ | Advanced Sampler Parameters (like Contrast/Sharpness/etc) | Advanced -> Advanced -> Sampling Sharpness / etc |
72
+ | User-friendly ControlNets | Input Image -> Image Prompt -> Advanced |
73
+
74
+ Fooocus also developed many "fooocus-only" features for advanced users to get perfect results. [Click here to browse the advanced features.](https://github.com/lllyasviel/Fooocus/discussions/117)
75
+
76
+ # Download
77
+
78
+ ### Windows
79
+
80
+ You can directly download Fooocus with:
81
+
82
+ **[>>> Click here to download <<<](https://github.com/lllyasviel/Fooocus/releases/download/release/Fooocus_win64_2-1-831.7z)**
83
+
84
+ After you download the file, please uncompress it and then run the "run.bat".
85
+
86
+ ![image](https://github.com/lllyasviel/Fooocus/assets/19834515/c49269c4-c274-4893-b368-047c401cc58c)
87
+
88
+ The first time you launch the software, it will automatically download models:
89
+
90
+ 1. It will download [default models](#models) to the folder "Fooocus\models\checkpoints" given different presets. You can download them in advance if you do not want automatic download.
91
+ 2. Note that if you use inpaint, at the first time you inpaint an image, it will download [Fooocus's own inpaint control model from here](https://huggingface.co/lllyasviel/fooocus_inpaint/resolve/main/inpaint_v26.fooocus.patch) as the file "Fooocus\models\inpaint\inpaint_v26.fooocus.patch" (the size of this file is 1.28GB).
92
+
93
+ After Fooocus 2.1.60, you will also have `run_anime.bat` and `run_realistic.bat`. They are different model presets (and require different models, but they will be automatically downloaded). [Check here for more details](https://github.com/lllyasviel/Fooocus/discussions/679).
94
+
95
+ ![image](https://github.com/lllyasviel/Fooocus/assets/19834515/d386f817-4bd7-490c-ad89-c1e228c23447)
96
+
97
+ If you already have these files, you can copy them to the above locations to speed up installation.
98
+
99
+ Note that if you see **"MetadataIncompleteBuffer" or "PytorchStreamReader"**, then your model files are corrupted. Please download models again.
100
+
101
+ Below is a test on a relatively low-end laptop with **16GB System RAM** and **6GB VRAM** (Nvidia 3060 laptop). The speed on this machine is about 1.35 seconds per iteration. Pretty impressive – nowadays laptops with 3060 are usually at very acceptable price.
102
+
103
+ ![image](https://github.com/lllyasviel/Fooocus/assets/19834515/938737a5-b105-4f19-b051-81356cb7c495)
104
+
105
+ Besides, recently many other software report that Nvidia driver above 532 is sometimes 10x slower than Nvidia driver 531. If your generation time is very long, consider download [Nvidia Driver 531 Laptop](https://www.nvidia.com/download/driverResults.aspx/199991/en-us/) or [Nvidia Driver 531 Desktop](https://www.nvidia.com/download/driverResults.aspx/199990/en-us/).
106
+
107
+ Note that the minimal requirement is **4GB Nvidia GPU memory (4GB VRAM)** and **8GB system memory (8GB RAM)**. This requires using Microsoft’s Virtual Swap technique, which is automatically enabled by your Windows installation in most cases, so you often do not need to do anything about it. However, if you are not sure, or if you manually turned it off (would anyone really do that?), or **if you see any "RuntimeError: CPUAllocator"**, you can enable it here:
108
+
109
+ <details>
110
+ <summary>Click here to see the image instructions. </summary>
111
+
112
+ ![image](https://github.com/lllyasviel/Fooocus/assets/19834515/2a06b130-fe9b-4504-94f1-2763be4476e9)
113
+
114
+ **And make sure that you have at least 40GB free space on each drive if you still see "RuntimeError: CPUAllocator" !**
115
+
116
+ </details>
117
+
118
+ Please open an issue if you use similar devices but still cannot achieve acceptable performances.
119
+
120
+ Note that the [minimal requirement](#minimal-requirement) for different platforms is different.
121
+
122
+ See also the common problems and troubleshoots [here](troubleshoot.md).
123
+
124
+ ### Colab
125
+
126
+ (Last tested - 2023 Dec 12)
127
+
128
+ | Colab | Info
129
+ | --- | --- |
130
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/lllyasviel/Fooocus/blob/main/fooocus_colab.ipynb) | Fooocus Official
131
+
132
+ In Colab, you can modify the last line to `!python entry_with_update.py --share` or `!python entry_with_update.py --preset anime --share` or `!python entry_with_update.py --preset realistic --share` for Fooocus Default/Anime/Realistic Edition.
133
+
134
+ Note that this Colab will disable refiner by default because Colab free's resources are relatively limited (and some "big" features like image prompt may cause free-tier Colab to disconnect). We make sure that basic text-to-image is always working on free-tier Colab.
135
+
136
+ Thanks to [camenduru](https://github.com/camenduru)!
137
+
138
+ ### Linux (Using Anaconda)
139
+
140
+ If you want to use Anaconda/Miniconda, you can
141
+
142
+ git clone https://github.com/lllyasviel/Fooocus.git
143
+ cd Fooocus
144
+ conda env create -f environment.yaml
145
+ conda activate fooocus
146
+ pip install -r requirements_versions.txt
147
+
148
+ Then download the models: download [default models](#models) to the folder "Fooocus\models\checkpoints". **Or let Fooocus automatically download the models** using the launcher:
149
+
150
+ conda activate fooocus
151
+ python entry_with_update.py
152
+
153
+ Or, if you want to open a remote port, use
154
+
155
+ conda activate fooocus
156
+ python entry_with_update.py --listen
157
+
158
+ Use `python entry_with_update.py --preset anime` or `python entry_with_update.py --preset realistic` for Fooocus Anime/Realistic Edition.
159
+
160
+ ### Linux (Using Python Venv)
161
+
162
+ Your Linux needs to have **Python 3.10** installed, and let's say your Python can be called with the command **python3** with your venv system working; you can
163
+
164
+ git clone https://github.com/lllyasviel/Fooocus.git
165
+ cd Fooocus
166
+ python3 -m venv fooocus_env
167
+ source fooocus_env/bin/activate
168
+ pip install -r requirements_versions.txt
169
+
170
+ See the above sections for model downloads. You can launch the software with:
171
+
172
+ source fooocus_env/bin/activate
173
+ python entry_with_update.py
174
+
175
+ Or, if you want to open a remote port, use
176
+
177
+ source fooocus_env/bin/activate
178
+ python entry_with_update.py --listen
179
+
180
+ Use `python entry_with_update.py --preset anime` or `python entry_with_update.py --preset realistic` for Fooocus Anime/Realistic Edition.
181
+
182
+ ### Linux (Using native system Python)
183
+
184
+ If you know what you are doing, and your Linux already has **Python 3.10** installed, and your Python can be called with the command **python3** (and Pip with **pip3**), you can
185
+
186
+ git clone https://github.com/lllyasviel/Fooocus.git
187
+ cd Fooocus
188
+ pip3 install -r requirements_versions.txt
189
+
190
+ See the above sections for model downloads. You can launch the software with:
191
+
192
+ python3 entry_with_update.py
193
+
194
+ Or, if you want to open a remote port, use
195
+
196
+ python3 entry_with_update.py --listen
197
+
198
+ Use `python entry_with_update.py --preset anime` or `python entry_with_update.py --preset realistic` for Fooocus Anime/Realistic Edition.
199
+
200
+ ### Linux (AMD GPUs)
201
+
202
+ Note that the [minimal requirement](#minimal-requirement) for different platforms is different.
203
+
204
+ Same with the above instructions. You need to change torch to the AMD version
205
+
206
+ pip uninstall torch torchvision torchaudio torchtext functorch xformers
207
+ pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm5.6
208
+
209
+ AMD is not intensively tested, however. The AMD support is in beta.
210
+
211
+ Use `python entry_with_update.py --preset anime` or `python entry_with_update.py --preset realistic` for Fooocus Anime/Realistic Edition.
212
+
213
+ ### Windows (AMD GPUs)
214
+
215
+ Note that the [minimal requirement](#minimal-requirement) for different platforms is different.
216
+
217
+ Same with Windows. Download the software and edit the content of `run.bat` as:
218
+
219
+ .\python_embeded\python.exe -m pip uninstall torch torchvision torchaudio torchtext functorch xformers -y
220
+ .\python_embeded\python.exe -m pip install torch-directml
221
+ .\python_embeded\python.exe -s Fooocus\entry_with_update.py --directml
222
+ pause
223
+
224
+ Then run the `run.bat`.
225
+
226
+ AMD is not intensively tested, however. The AMD support is in beta.
227
+
228
+ For AMD, use `.\python_embeded\python.exe entry_with_update.py --directml --preset anime` or `.\python_embeded\python.exe entry_with_update.py --directml --preset realistic` for Fooocus Anime/Realistic Edition.
229
+
230
+ ### Mac
231
+
232
+ Note that the [minimal requirement](#minimal-requirement) for different platforms is different.
233
+
234
+ Mac is not intensively tested. Below is an unofficial guideline for using Mac. You can discuss problems [here](https://github.com/lllyasviel/Fooocus/pull/129).
235
+
236
+ You can install Fooocus on Apple Mac silicon (M1 or M2) with macOS 'Catalina' or a newer version. Fooocus runs on Apple silicon computers via [PyTorch](https://pytorch.org/get-started/locally/) MPS device acceleration. Mac Silicon computers don't come with a dedicated graphics card, resulting in significantly longer image processing times compared to computers with dedicated graphics cards.
237
+
238
+ 1. Install the conda package manager and pytorch nightly. Read the [Accelerated PyTorch training on Mac](https://developer.apple.com/metal/pytorch/) Apple Developer guide for instructions. Make sure pytorch recognizes your MPS device.
239
+ 1. Open the macOS Terminal app and clone this repository with `git clone https://github.com/lllyasviel/Fooocus.git`.
240
+ 1. Change to the new Fooocus directory, `cd Fooocus`.
241
+ 1. Create a new conda environment, `conda env create -f environment.yaml`.
242
+ 1. Activate your new conda environment, `conda activate fooocus`.
243
+ 1. Install the packages required by Fooocus, `pip install -r requirements_versions.txt`.
244
+ 1. Launch Fooocus by running `python entry_with_update.py`. (Some Mac M2 users may need `python entry_with_update.py --disable-offload-from-vram` to speed up model loading/unloading.) The first time you run Fooocus, it will automatically download the Stable Diffusion SDXL models and will take a significant amount of time, depending on your internet connection.
245
+
246
+ Use `python entry_with_update.py --preset anime` or `python entry_with_update.py --preset realistic` for Fooocus Anime/Realistic Edition.
247
+
248
+ ### Docker
249
+
250
+ See [docker.md](docker.md)
251
+
252
+ ### Download Previous Version
253
+
254
+ See the guidelines [here](https://github.com/lllyasviel/Fooocus/discussions/1405).
255
+
256
+ ## Minimal Requirement
257
+
258
+ Below is the minimal requirement for running Fooocus locally. If your device capability is lower than this spec, you may not be able to use Fooocus locally. (Please let us know, in any case, if your device capability is lower but Fooocus still works.)
259
+
260
+ | Operating System | GPU | Minimal GPU Memory | Minimal System Memory | [System Swap](troubleshoot.md) | Note |
261
+ |-------------------|------------------------------|------------------------------|---------------------------|--------------------------------|----------------------------------------------------------------------------|
262
+ | Windows/Linux | Nvidia RTX 4XXX | 4GB | 8GB | Required | fastest |
263
+ | Windows/Linux | Nvidia RTX 3XXX | 4GB | 8GB | Required | usually faster than RTX 2XXX |
264
+ | Windows/Linux | Nvidia RTX 2XXX | 4GB | 8GB | Required | usually faster than GTX 1XXX |
265
+ | Windows/Linux | Nvidia GTX 1XXX | 8GB (&ast; 6GB uncertain) | 8GB | Required | only marginally faster than CPU |
266
+ | Windows/Linux | Nvidia GTX 9XX | 8GB | 8GB | Required | faster or slower than CPU |
267
+ | Windows/Linux | Nvidia GTX < 9XX | Not supported | / | / | / |
268
+ | Windows | AMD GPU | 8GB (updated 2023 Dec 30) | 8GB | Required | via DirectML (&ast; ROCm is on hold), about 3x slower than Nvidia RTX 3XXX |
269
+ | Linux | AMD GPU | 8GB | 8GB | Required | via ROCm, about 1.5x slower than Nvidia RTX 3XXX |
270
+ | Mac | M1/M2 MPS | Shared | Shared | Shared | about 9x slower than Nvidia RTX 3XXX |
271
+ | Windows/Linux/Mac | only use CPU | 0GB | 32GB | Required | about 17x slower than Nvidia RTX 3XXX |
272
+
273
+ &ast; AMD GPU ROCm (on hold): The AMD is still working on supporting ROCm on Windows.
274
+
275
+ &ast; Nvidia GTX 1XXX 6GB uncertain: Some people report 6GB success on GTX 10XX, but some other people report failure cases.
276
+
277
+ *Note that Fooocus is only for extremely high quality image generating. We will not support smaller models to reduce the requirement and sacrifice result quality.*
278
+
279
+ ## Troubleshoot
280
+
281
+ See the common problems [here](troubleshoot.md).
282
+
283
+ ## Default Models
284
+ <a name="models"></a>
285
+
286
+ Given different goals, the default models and configs of Fooocus are different:
287
+
288
+ | Task | Windows | Linux args | Main Model | Refiner | Config |
289
+ | --- | --- | --- | --- | --- |--------------------------------------------------------------------------------|
290
+ | General | run.bat | | juggernautXL_v8Rundiffusion | not used | [here](https://github.com/lllyasviel/Fooocus/blob/main/presets/default.json) |
291
+ | Realistic | run_realistic.bat | --preset realistic | realisticStockPhoto_v20 | not used | [here](https://github.com/lllyasviel/Fooocus/blob/main/presets/realistic.json) |
292
+ | Anime | run_anime.bat | --preset anime | animaPencilXL_v100 | not used | [here](https://github.com/lllyasviel/Fooocus/blob/main/presets/anime.json) |
293
+
294
+ Note that the download is **automatic** - you do not need to do anything if the internet connection is okay. However, you can download them manually if you (or move them from somewhere else) have your own preparation.
295
+
296
+ ## UI Access and Authentication
297
+ In addition to running on localhost, Fooocus can also expose its UI in two ways:
298
+ * Local UI listener: use `--listen` (specify port e.g. with `--port 8888`).
299
+ * API access: use `--share` (registers an endpoint at `.gradio.live`).
300
+
301
+ In both ways the access is unauthenticated by default. You can add basic authentication by creating a file called `auth.json` in the main directory, which contains a list of JSON objects with the keys `user` and `pass` (see example in [auth-example.json](./auth-example.json)).
302
+
303
+ ## List of "Hidden" Tricks
304
+ <a name="tech_list"></a>
305
+
306
+ The below things are already inside the software, and **users do not need to do anything about these**.
307
+
308
+ 1. GPT2-based [prompt expansion as a dynamic style "Fooocus V2".](https://github.com/lllyasviel/Fooocus/discussions/117#raw) (similar to Midjourney's hidden pre-processing and "raw" mode, or the LeonardoAI's Prompt Magic).
309
+ 2. Native refiner swap inside one single k-sampler. The advantage is that the refiner model can now reuse the base model's momentum (or ODE's history parameters) collected from k-sampling to achieve more coherent sampling. In Automatic1111's high-res fix and ComfyUI's node system, the base model and refiner use two independent k-samplers, which means the momentum is largely wasted, and the sampling continuity is broken. Fooocus uses its own advanced k-diffusion sampling that ensures seamless, native, and continuous swap in a refiner setup. (Update Aug 13: Actually, I discussed this with Automatic1111 several days ago, and it seems that the “native refiner swap inside one single k-sampler” is [merged]( https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/12371) into the dev branch of webui. Great!)
310
+ 3. Negative ADM guidance. Because the highest resolution level of XL Base does not have cross attentions, the positive and negative signals for XL's highest resolution level cannot receive enough contrasts during the CFG sampling, causing the results to look a bit plastic or overly smooth in certain cases. Fortunately, since the XL's highest resolution level is still conditioned on image aspect ratios (ADM), we can modify the adm on the positive/negative side to compensate for the lack of CFG contrast in the highest resolution level. (Update Aug 16, the IOS App [Draw Things](https://apps.apple.com/us/app/draw-things-ai-generation/id6444050820) will support Negative ADM Guidance. Great!)
311
+ 4. We implemented a carefully tuned variation of Section 5.1 of ["Improving Sample Quality of Diffusion Models Using Self-Attention Guidance"](https://arxiv.org/pdf/2210.00939.pdf). The weight is set to very low, but this is Fooocus's final guarantee to make sure that the XL will never yield an overly smooth or plastic appearance (examples [here](https://github.com/lllyasviel/Fooocus/discussions/117#sharpness)). This can almost eliminate all cases for which XL still occasionally produces overly smooth results, even with negative ADM guidance. (Update 2023 Aug 18, the Gaussian kernel of SAG is changed to an anisotropic kernel for better structure preservation and fewer artifacts.)
312
+ 5. We modified the style templates a bit and added the "cinematic-default".
313
+ 6. We tested the "sd_xl_offset_example-lora_1.0.safetensors" and it seems that when the lora weight is below 0.5, the results are always better than XL without lora.
314
+ 7. The parameters of samplers are carefully tuned.
315
+ 8. Because XL uses positional encoding for generation resolution, images generated by several fixed resolutions look a bit better than those from arbitrary resolutions (because the positional encoding is not very good at handling int numbers that are unseen during training). This suggests that the resolutions in UI may be hard coded for best results.
316
+ 9. Separated prompts for two different text encoders seem unnecessary. Separated prompts for the base model and refiner may work, but the effects are random, and we refrain from implementing this.
317
+ 10. The DPM family seems well-suited for XL since XL sometimes generates overly smooth texture, but the DPM family sometimes generates overly dense detail in texture. Their joint effect looks neutral and appealing to human perception.
318
+ 11. A carefully designed system for balancing multiple styles as well as prompt expansion.
319
+ 12. Using automatic1111's method to normalize prompt emphasizing. This significantly improves results when users directly copy prompts from civitai.
320
+ 13. The joint swap system of the refiner now also supports img2img and upscale in a seamless way.
321
+ 14. CFG Scale and TSNR correction (tuned for SDXL) when CFG is bigger than 10.
322
+
323
+ ## Customization
324
+
325
+ After the first time you run Fooocus, a config file will be generated at `Fooocus\config.txt`. This file can be edited to change the model path or default parameters.
326
+
327
+ For example, an edited `Fooocus\config.txt` (this file will be generated after the first launch) may look like this:
328
+
329
+ ```json
330
+ {
331
+ "path_checkpoints": "D:\\Fooocus\\models\\checkpoints",
332
+ "path_loras": "D:\\Fooocus\\models\\loras",
333
+ "path_embeddings": "D:\\Fooocus\\models\\embeddings",
334
+ "path_vae_approx": "D:\\Fooocus\\models\\vae_approx",
335
+ "path_upscale_models": "D:\\Fooocus\\models\\upscale_models",
336
+ "path_inpaint": "D:\\Fooocus\\models\\inpaint",
337
+ "path_controlnet": "D:\\Fooocus\\models\\controlnet",
338
+ "path_clip_vision": "D:\\Fooocus\\models\\clip_vision",
339
+ "path_fooocus_expansion": "D:\\Fooocus\\models\\prompt_expansion\\fooocus_expansion",
340
+ "path_outputs": "D:\\Fooocus\\outputs",
341
+ "default_model": "realisticStockPhoto_v10.safetensors",
342
+ "default_refiner": "",
343
+ "default_loras": [["lora_filename_1.safetensors", 0.5], ["lora_filename_2.safetensors", 0.5]],
344
+ "default_cfg_scale": 3.0,
345
+ "default_sampler": "dpmpp_2m",
346
+ "default_scheduler": "karras",
347
+ "default_negative_prompt": "low quality",
348
+ "default_positive_prompt": "",
349
+ "default_styles": [
350
+ "Fooocus V2",
351
+ "Fooocus Photograph",
352
+ "Fooocus Negative"
353
+ ]
354
+ }
355
+ ```
356
+
357
+ Many other keys, formats, and examples are in `Fooocus\config_modification_tutorial.txt` (this file will be generated after the first launch).
358
+
359
+ Consider twice before you really change the config. If you find yourself breaking things, just delete `Fooocus\config.txt`. Fooocus will go back to default.
360
+
361
+ A safer way is just to try "run_anime.bat" or "run_realistic.bat" - they should already be good enough for different tasks.
362
+
363
+ ~Note that `user_path_config.txt` is deprecated and will be removed soon.~ (Edit: it is already removed.)
364
+
365
+ ### All CMD Flags
366
+
367
+ ```
368
+ entry_with_update.py [-h] [--listen [IP]] [--port PORT]
369
+ [--disable-header-check [ORIGIN]]
370
+ [--web-upload-size WEB_UPLOAD_SIZE]
371
+ [--external-working-path PATH [PATH ...]]
372
+ [--output-path OUTPUT_PATH] [--temp-path TEMP_PATH]
373
+ [--cache-path CACHE_PATH] [--in-browser]
374
+ [--disable-in-browser] [--gpu-device-id DEVICE_ID]
375
+ [--async-cuda-allocation | --disable-async-cuda-allocation]
376
+ [--disable-attention-upcast] [--all-in-fp32 | --all-in-fp16]
377
+ [--unet-in-bf16 | --unet-in-fp16 | --unet-in-fp8-e4m3fn | --unet-in-fp8-e5m2]
378
+ [--vae-in-fp16 | --vae-in-fp32 | --vae-in-bf16]
379
+ [--clip-in-fp8-e4m3fn | --clip-in-fp8-e5m2 | --clip-in-fp16 | --clip-in-fp32]
380
+ [--directml [DIRECTML_DEVICE]] [--disable-ipex-hijack]
381
+ [--preview-option [none,auto,fast,taesd]]
382
+ [--attention-split | --attention-quad | --attention-pytorch]
383
+ [--disable-xformers]
384
+ [--always-gpu | --always-high-vram | --always-normal-vram |
385
+ --always-low-vram | --always-no-vram | --always-cpu [CPU_NUM_THREADS]]
386
+ [--always-offload-from-vram] [--disable-server-log]
387
+ [--debug-mode] [--is-windows-embedded-python]
388
+ [--disable-server-info] [--share] [--preset PRESET]
389
+ [--language LANGUAGE] [--disable-offload-from-vram]
390
+ [--theme THEME] [--disable-image-log]
391
+ ```
392
+
393
+ ## Advanced Features
394
+
395
+ [Click here to browse the advanced features.](https://github.com/lllyasviel/Fooocus/discussions/117)
396
+
397
+ Fooocus also has many community forks, just like SD-WebUI's [vladmandic/automatic](https://github.com/vladmandic/automatic) and [anapnoe/stable-diffusion-webui-ux](https://github.com/anapnoe/stable-diffusion-webui-ux), for enthusiastic users who want to try!
398
+
399
+ | Fooocus' forks |
400
+ | - |
401
+ | [fenneishi/Fooocus-Control](https://github.com/fenneishi/Fooocus-Control) </br>[runew0lf/RuinedFooocus](https://github.com/runew0lf/RuinedFooocus) </br> [MoonRide303/Fooocus-MRE](https://github.com/MoonRide303/Fooocus-MRE) </br> [metercai/SimpleSDXL](https://github.com/metercai/SimpleSDXL) </br> and so on ... |
402
+
403
+ See also [About Forking and Promotion of Forks](https://github.com/lllyasviel/Fooocus/discussions/699).
404
+
405
+ ## Thanks
406
+
407
+ Special thanks to [twri](https://github.com/twri) and [3Diva](https://github.com/3Diva) and [Marc K3nt3L](https://github.com/K3nt3L) for creating additional SDXL styles available in Fooocus. Thanks [daswer123](https://github.com/daswer123) for contributing the Canvas Zoom!
408
+
409
+ ## Update Log
410
+
411
+ The log is [here](update_log.md).
412
+
413
+ ## Localization/Translation/I18N
414
+
415
+ **We need your help!** Please help translate Fooocus into international languages.
416
+
417
+ You can put json files in the `language` folder to translate the user interface.
418
+
419
+ For example, below is the content of `Fooocus/language/example.json`:
420
+
421
+ ```json
422
+ {
423
+ "Generate": "生成",
424
+ "Input Image": "入力画像",
425
+ "Advanced": "고급",
426
+ "SAI 3D Model": "SAI 3D Modèle"
427
+ }
428
+ ```
429
+
430
+ If you add `--language example` arg, Fooocus will read `Fooocus/language/example.json` to translate the UI.
431
+
432
+ For example, you can edit the ending line of Windows `run.bat` as
433
+
434
+ .\python_embeded\python.exe -s Fooocus\entry_with_update.py --language example
435
+
436
+ Or `run_anime.bat` as
437
+
438
+ .\python_embeded\python.exe -s Fooocus\entry_with_update.py --language example --preset anime
439
+
440
+ Or `run_realistic.bat` as
441
+
442
+ .\python_embeded\python.exe -s Fooocus\entry_with_update.py --language example --preset realistic
443
+
444
+ For practical translation, you may create your own file like `Fooocus/language/jp.json` or `Fooocus/language/cn.json` and then use flag `--language jp` or `--language cn`. Apparently, these files do not exist now. **We need your help to create these files!**
445
+
446
+ Note that if no `--language` is given and at the same time `Fooocus/language/default.json` exists, Fooocus will always load `Fooocus/language/default.json` for translation. By default, the file `Fooocus/language/default.json` does not exist.
requirements_versions.txt ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ torchsde==0.2.5
2
+ einops==0.4.1
3
+ transformers==4.30.2
4
+ safetensors==0.3.1
5
+ accelerate==0.21.0
6
+ pyyaml==6.0
7
+ Pillow==9.2.0
8
+ scipy==1.9.3
9
+ tqdm==4.64.1
10
+ psutil==5.9.5
11
+ pytorch_lightning==1.9.4
12
+ omegaconf==2.2.3
13
+ gradio==3.41.2
14
+ pygit2==1.12.2
15
+ opencv-contrib-python==4.8.0.74
16
+ httpx==0.24.1
17
+ onnxruntime==1.16.3
18
+ timm==0.9.2
webui.py CHANGED
@@ -15,12 +15,703 @@ import modules.style_sorter as style_sorter
15
  import modules.meta_parser
16
  import args_manager
17
  import copy
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  from modules.sdxl_styles import legal_style_names
20
  from modules.private_logger import get_current_html_path
21
  from modules.ui_gradio_extensions import reload_javascript
22
  from modules.auth import auth_enabled, check_auth
23
  from modules.util import is_json
 
24
  def get_task(*args):
25
  args = list(args)
26
  args.pop(0)
@@ -674,9 +1365,9 @@ def dump_default_english_config():
674
  dump_english_config(grh.all_components)
675
 
676
 
677
- # dump_default_englishn_config()
678
-
679
- shared.gradio_root.launch(
680
  inbrowser=args_manager.args.in_browser,
681
  server_name=args_manager.args.listen,
682
  server_port=args_manager.args.port,
@@ -685,3 +1376,5 @@ shared.gradio_root.launch(
685
  allowed_paths=[modules.config.path_outputs],
686
  blocked_paths=[constants.AUTH_FILENAME]
687
  )
 
 
 
15
  import modules.meta_parser
16
  import args_manager
17
  import copy
18
+ from gradio import Interface
19
+ from modules.sdxl_styles import legal_style_names
20
+ from modules.private_logger import get_current_html_path
21
+ from modules.ui_gradio_extensions import reload_javascript
22
+ from modules.auth import auth_enabled, check_auth
23
+ from modules.util import is_json
24
+
25
+ def get_task(*args):
26
+ args = list(args)
27
+ args.pop(0)
28
+
29
+ return worker.AsyncTask(args=args)
30
+
31
+ def generate_clicked(task):
32
+ import ldm_patched.modules.model_management as model_management
33
+
34
+ with model_management.interrupt_processing_mutex:
35
+ model_management.interrupt_processing = False
36
+ # outputs=[progress_html, progress_window, progress_gallery, gallery]
37
+ execution_start_time = time.perf_counter()
38
+ finished = False
39
+
40
+ yield gr.update(visible=True, value=modules.html.make_progress_html(1, 'Waiting for task to start ...')), \
41
+ gr.update(visible=True, value=None), \
42
+ gr.update(visible=False, value=None), \
43
+ gr.update(visible=False)
44
+
45
+ worker.async_tasks.append(task)
46
+
47
+ while not finished:
48
+ time.sleep(0.01)
49
+ if len(task.yields) > 0:
50
+ flag, product = task.yields.pop(0)
51
+ if flag == 'preview':
52
+
53
+ # help bad internet connection by skipping duplicated preview
54
+ if len(task.yields) > 0: # if we have the next item
55
+ if task.yields[0][0] == 'preview': # if the next item is also a preview
56
+ # print('Skipped one preview for better internet connection.')
57
+ continue
58
+
59
+ percentage, title, image = product
60
+ yield gr.update(visible=True, value=modules.html.make_progress_html(percentage, title)), \
61
+ gr.update(visible=True, value=image) if image is not None else gr.update(), \
62
+ gr.update(), \
63
+ gr.update(visible=False)
64
+ if flag == 'results':
65
+ yield gr.update(visible=True), \
66
+ gr.update(visible=True), \
67
+ gr.update(visible=True, value=product), \
68
+ gr.update(visible=False)
69
+ if flag == 'finish':
70
+ yield gr.update(visible=False), \
71
+ gr.update(visible=False), \
72
+ gr.update(visible=False), \
73
+ gr.update(visible=True, value=product)
74
+ finished = True
75
+
76
+ # delete Fooocus temp images, only keep gradio temp images
77
+ if args_manager.args.disable_image_log:
78
+ for filepath in product:
79
+ if isinstance(filepath, str) and os.path.exists(filepath):
80
+ os.remove(filepath)
81
+
82
+ execution_time = time.perf_counter() - execution_start_time
83
+ print(f'Total time: {execution_time:.2f} seconds')
84
+ return
85
+
86
+
87
+ reload_javascript()
88
+
89
+ title = f'Fooocus {fooocus_version.version}'
90
+
91
+ if isinstance(args_manager.args.preset, str):
92
+ title += ' ' + args_manager.args.preset
93
+
94
+ shared.gradio_root = gr.Blocks(
95
+ title=title,
96
+ css=modules.html.css).queue()
97
+
98
+ with shared.gradio_root:
99
+ currentTask = gr.State(worker.AsyncTask(args=[]))
100
+ with gr.Row():
101
+ with gr.Column(scale=2):
102
+ with gr.Row():
103
+ progress_window = grh.Image(label='Preview', show_label=True, visible=False, height=768,
104
+ elem_classes=['main_view'])
105
+ progress_gallery = gr.Gallery(label='Finished Images', show_label=True, object_fit='contain',
106
+ height=768, visible=False, elem_classes=['main_view', 'image_gallery'])
107
+ progress_html = gr.HTML(value=modules.html.make_progress_html(32, 'Progress 32%'), visible=False,
108
+ elem_id='progress-bar', elem_classes='progress-bar')
109
+ gallery = gr.Gallery(label='Gallery', show_label=False, object_fit='contain', visible=True, height=768,
110
+ elem_classes=['resizable_area', 'main_view', 'final_gallery', 'image_gallery'],
111
+ elem_id='final_gallery')
112
+ with gr.Row(elem_classes='type_row'):
113
+ with gr.Column(scale=17):
114
+ prompt = gr.Textbox(show_label=False, placeholder="Type prompt here or paste parameters.", elem_id='positive_prompt',
115
+ container=False, autofocus=True, elem_classes='type_row', lines=1024)
116
+
117
+ default_prompt = modules.config.default_prompt
118
+ if isinstance(default_prompt, str) and default_prompt != '':
119
+ shared.gradio_root.load(lambda: default_prompt, outputs=prompt)
120
+
121
+ with gr.Column(scale=3, min_width=0):
122
+ generate_button = gr.Button(label="Generate", value="Generate", elem_classes='type_row', elem_id='generate_button', visible=True)
123
+ load_parameter_button = gr.Button(label="Load Parameters", value="Load Parameters", elem_classes='type_row', elem_id='load_parameter_button', visible=False)
124
+ skip_button = gr.Button(label="Skip", value="Skip", elem_classes='type_row_half', visible=False)
125
+ stop_button = gr.Button(label="Stop", value="Stop", elem_classes='type_row_half', elem_id='stop_button', visible=False)
126
+
127
+ def stop_clicked(currentTask):
128
+ import ldm_patched.modules.model_management as model_management
129
+ currentTask.last_stop = 'stop'
130
+ if (currentTask.processing):
131
+ model_management.interrupt_current_processing()
132
+ return currentTask
133
+
134
+ def skip_clicked(currentTask):
135
+ import ldm_patched.modules.model_management as model_management
136
+ currentTask.last_stop = 'skip'
137
+ if (currentTask.processing):
138
+ model_management.interrupt_current_processing()
139
+ return currentTask
140
+
141
+ stop_button.click(stop_clicked, inputs=currentTask, outputs=currentTask, queue=False, show_progress=False, _js='cancelGenerateForever')
142
+ skip_button.click(skip_clicked, inputs=currentTask, outputs=currentTask, queue=False, show_progress=False)
143
+ with gr.Row(elem_classes='advanced_check_row'):
144
+ input_image_checkbox = gr.Checkbox(label='Input Image', value=False, container=False, elem_classes='min_check')
145
+ advanced_checkbox = gr.Checkbox(label='Advanced', value=modules.config.default_advanced_checkbox, container=False, elem_classes='min_check')
146
+ with gr.Row(visible=False) as image_input_panel:
147
+ with gr.Tabs():
148
+ with gr.TabItem(label='Upscale or Variation') as uov_tab:
149
+ with gr.Row():
150
+ with gr.Column():
151
+ uov_input_image = grh.Image(label='Drag above image to here', source='upload', type='numpy')
152
+ with gr.Column():
153
+ uov_method = gr.Radio(label='Upscale or Variation:', choices=flags.uov_list, value=flags.disabled)
154
+ gr.HTML('<a href="https://github.com/lllyasviel/Fooocus/discussions/390" target="_blank">\U0001F4D4 Document</a>')
155
+ with gr.TabItem(label='Image Prompt') as ip_tab:
156
+ with gr.Row():
157
+ ip_images = []
158
+ ip_types = []
159
+ ip_stops = []
160
+ ip_weights = []
161
+ ip_ctrls = []
162
+ ip_ad_cols = []
163
+ for _ in range(flags.controlnet_image_count):
164
+ with gr.Column():
165
+ ip_image = grh.Image(label='Image', source='upload', type='numpy', show_label=False, height=300)
166
+ ip_images.append(ip_image)
167
+ ip_ctrls.append(ip_image)
168
+ with gr.Column(visible=False) as ad_col:
169
+ with gr.Row():
170
+ default_end, default_weight = flags.default_parameters[flags.default_ip]
171
+
172
+ ip_stop = gr.Slider(label='Stop At', minimum=0.0, maximum=1.0, step=0.001, value=default_end)
173
+ ip_stops.append(ip_stop)
174
+ ip_ctrls.append(ip_stop)
175
+
176
+ ip_weight = gr.Slider(label='Weight', minimum=0.0, maximum=2.0, step=0.001, value=default_weight)
177
+ ip_weights.append(ip_weight)
178
+ ip_ctrls.append(ip_weight)
179
+
180
+ ip_type = gr.Radio(label='Type', choices=flags.ip_list, value=flags.default_ip, container=False)
181
+ ip_types.append(ip_type)
182
+ ip_ctrls.append(ip_type)
183
+
184
+ ip_type.change(lambda x: flags.default_parameters[x], inputs=[ip_type], outputs=[ip_stop, ip_weight], queue=False, show_progress=False)
185
+ ip_ad_cols.append(ad_col)
186
+ ip_advanced = gr.Checkbox(label='Advanced', value=False, container=False)
187
+ gr.HTML('* \"Image Prompt\" is powered by Fooocus Image Mixture Engine (v1.0.1). <a href="https://github.com/lllyasviel/Fooocus/discussions/557" target="_blank">\U0001F4D4 Document</a>')
188
+
189
+ def ip_advance_checked(x):
190
+ return [gr.update(visible=x)] * len(ip_ad_cols) + \
191
+ [flags.default_ip] * len(ip_types) + \
192
+ [flags.default_parameters[flags.default_ip][0]] * len(ip_stops) + \
193
+ [flags.default_parameters[flags.default_ip][1]] * len(ip_weights)
194
+
195
+ ip_advanced.change(ip_advance_checked, inputs=ip_advanced,
196
+ outputs=ip_ad_cols + ip_types + ip_stops + ip_weights,
197
+ queue=False, show_progress=False)
198
+ with gr.TabItem(label='Inpaint or Outpaint') as inpaint_tab:
199
+ with gr.Row():
200
+ inpaint_input_image = grh.Image(label='Drag inpaint or outpaint image to here', source='upload', type='numpy', tool='sketch', height=500, brush_color="#FFFFFF", elem_id='inpaint_canvas')
201
+ inpaint_mask_image = grh.Image(label='Mask Upload', source='upload', type='numpy', height=500, visible=False)
202
+
203
+ with gr.Row():
204
+ inpaint_additional_prompt = gr.Textbox(placeholder="Describe what you want to inpaint.", elem_id='inpaint_additional_prompt', label='Inpaint Additional Prompt', visible=False)
205
+ outpaint_selections = gr.CheckboxGroup(choices=['Left', 'Right', 'Top', 'Bottom'], value=[], label='Outpaint Direction')
206
+ inpaint_mode = gr.Dropdown(choices=modules.flags.inpaint_options, value=modules.flags.inpaint_option_default, label='Method')
207
+ example_inpaint_prompts = gr.Dataset(samples=modules.config.example_inpaint_prompts, label='Additional Prompt Quick List', components=[inpaint_additional_prompt], visible=False)
208
+ gr.HTML('* Powered by Fooocus Inpaint Engine <a href="https://github.com/lllyasviel/Fooocus/discussions/414" target="_blank">\U0001F4D4 Document</a>')
209
+ example_inpaint_prompts.click(lambda x: x[0], inputs=example_inpaint_prompts, outputs=inpaint_additional_prompt, show_progress=False, queue=False)
210
+ with gr.TabItem(label='Describe') as desc_tab:
211
+ with gr.Row():
212
+ with gr.Column():
213
+ desc_input_image = grh.Image(label='Drag any image to here', source='upload', type='numpy')
214
+ with gr.Column():
215
+ desc_method = gr.Radio(
216
+ label='Content Type',
217
+ choices=[flags.desc_type_photo, flags.desc_type_anime],
218
+ value=flags.desc_type_photo)
219
+ desc_btn = gr.Button(value='Describe this Image into Prompt')
220
+ gr.HTML('<a href="https://github.com/lllyasviel/Fooocus/discussions/1363" target="_blank">\U0001F4D4 Document</a>')
221
+ with gr.TabItem(label='Metadata') as load_tab:
222
+ with gr.Column():
223
+ metadata_input_image = grh.Image(label='Drag any image generated by Fooocus here', source='upload', type='filepath')
224
+ metadata_json = gr.JSON(label='Metadata')
225
+ metadata_import_button = gr.Button(value='Apply Metadata')
226
+
227
+ def trigger_metadata_preview(filepath):
228
+ parameters, metadata_scheme = modules.meta_parser.read_info_from_image(filepath)
229
+
230
+ results = {}
231
+ if parameters is not None:
232
+ results['parameters'] = parameters
233
+
234
+ if isinstance(metadata_scheme, flags.MetadataScheme):
235
+ results['metadata_scheme'] = metadata_scheme.value
236
+
237
+ return results
238
+
239
+ metadata_input_image.upload(trigger_metadata_preview, inputs=metadata_input_image,
240
+ outputs=metadata_json, queue=False, show_progress=True)
241
+
242
+ switch_js = "(x) => {if(x){viewer_to_bottom(100);viewer_to_bottom(500);}else{viewer_to_top();} return x;}"
243
+ down_js = "() => {viewer_to_bottom();}"
244
+
245
+ input_image_checkbox.change(lambda x: gr.update(visible=x), inputs=input_image_checkbox,
246
+ outputs=image_input_panel, queue=False, show_progress=False, _js=switch_js)
247
+ ip_advanced.change(lambda: None, queue=False, show_progress=False, _js=down_js)
248
+
249
+ current_tab = gr.Textbox(value='uov', visible=False)
250
+ uov_tab.select(lambda: 'uov', outputs=current_tab, queue=False, _js=down_js, show_progress=False)
251
+ inpaint_tab.select(lambda: 'inpaint', outputs=current_tab, queue=False, _js=down_js, show_progress=False)
252
+ ip_tab.select(lambda: 'ip', outputs=current_tab, queue=False, _js=down_js, show_progress=False)
253
+ desc_tab.select(lambda: 'desc', outputs=current_tab, queue=False, _js=down_js, show_progress=False)
254
+
255
+ with gr.Column(scale=1, visible=modules.config.default_advanced_checkbox) as advanced_column:
256
+ with gr.Tab(label='Setting'):
257
+ performance_selection = gr.Radio(label='Performance',
258
+ choices=modules.flags.performance_selections,
259
+ value=modules.config.default_performance)
260
+ aspect_ratios_selection = gr.Radio(label='Aspect Ratios', choices=modules.config.available_aspect_ratios,
261
+ value=modules.config.default_aspect_ratio, info='width × height',
262
+ elem_classes='aspect_ratios')
263
+ image_number = gr.Slider(label='Image Number', minimum=1, maximum=modules.config.default_max_image_number, step=1, value=modules.config.default_image_number)
264
+
265
+ output_format = gr.Radio(label='Output Format',
266
+ choices=modules.flags.output_formats,
267
+ value=modules.config.default_output_format)
268
+
269
+ negative_prompt = gr.Textbox(label='Negative Prompt', show_label=True, placeholder="Type prompt here.",
270
+ info='Describing what you do not want to see.', lines=2,
271
+ elem_id='negative_prompt',
272
+ value=modules.config.default_prompt_negative)
273
+ seed_random = gr.Checkbox(label='Random', value=True)
274
+ image_seed = gr.Textbox(label='Seed', value=0, max_lines=1, visible=False) # workaround for https://github.com/gradio-app/gradio/issues/5354
275
+
276
+ def random_checked(r):
277
+ return gr.update(visible=not r)
278
+
279
+ def refresh_seed(r, seed_string):
280
+ if r:
281
+ return random.randint(constants.MIN_SEED, constants.MAX_SEED)
282
+ else:
283
+ try:
284
+ seed_value = int(seed_string)
285
+ if constants.MIN_SEED <= seed_value <= constants.MAX_SEED:
286
+ return seed_value
287
+ except ValueError:
288
+ pass
289
+ return random.randint(constants.MIN_SEED, constants.MAX_SEED)
290
+
291
+ seed_random.change(random_checked, inputs=[seed_random], outputs=[image_seed],
292
+ queue=False, show_progress=False)
293
+
294
+ def update_history_link():
295
+ if args_manager.args.disable_image_log:
296
+ return gr.update(value='')
297
+
298
+ return gr.update(value=f'<a href="file={get_current_html_path(output_format)}" target="_blank">\U0001F4DA History Log</a>')
299
+
300
+ history_link = gr.HTML()
301
+ shared.gradio_root.load(update_history_link, outputs=history_link, queue=False, show_progress=False)
302
+
303
+ with gr.Tab(label='Style'):
304
+ style_sorter.try_load_sorted_styles(
305
+ style_names=legal_style_names,
306
+ default_selected=modules.config.default_styles)
307
+
308
+ style_search_bar = gr.Textbox(show_label=False, container=False,
309
+ placeholder="\U0001F50E Type here to search styles ...",
310
+ value="",
311
+ label='Search Styles')
312
+ style_selections = gr.CheckboxGroup(show_label=False, container=False,
313
+ choices=copy.deepcopy(style_sorter.all_styles),
314
+ value=copy.deepcopy(modules.config.default_styles),
315
+ label='Selected Styles',
316
+ elem_classes=['style_selections'])
317
+ gradio_receiver_style_selections = gr.Textbox(elem_id='gradio_receiver_style_selections', visible=False)
318
+
319
+ shared.gradio_root.load(lambda: gr.update(choices=copy.deepcopy(style_sorter.all_styles)),
320
+ outputs=style_selections)
321
+
322
+ style_search_bar.change(style_sorter.search_styles,
323
+ inputs=[style_selections, style_search_bar],
324
+ outputs=style_selections,
325
+ queue=False,
326
+ show_progress=False).then(
327
+ lambda: None, _js='()=>{refresh_style_localization();}')
328
+
329
+ gradio_receiver_style_selections.input(style_sorter.sort_styles,
330
+ inputs=style_selections,
331
+ outputs=style_selections,
332
+ queue=False,
333
+ show_progress=False).then(
334
+ lambda: None, _js='()=>{refresh_style_localization();}')
335
+
336
+ with gr.Tab(label='Model'):
337
+ with gr.Group():
338
+ with gr.Row():
339
+ base_model = gr.Dropdown(label='Base Model (SDXL only)', choices=modules.config.model_filenames, value=modules.config.default_base_model_name, show_label=True)
340
+ refiner_model = gr.Dropdown(label='Refiner (SDXL or SD 1.5)', choices=['None'] + modules.config.model_filenames, value=modules.config.default_refiner_model_name, show_label=True)
341
+
342
+ refiner_switch = gr.Slider(label='Refiner Switch At', minimum=0.1, maximum=1.0, step=0.0001,
343
+ info='Use 0.4 for SD1.5 realistic models; '
344
+ 'or 0.667 for SD1.5 anime models; '
345
+ 'or 0.8 for XL-refiners; '
346
+ 'or any value for switching two SDXL models.',
347
+ value=modules.config.default_refiner_switch,
348
+ visible=modules.config.default_refiner_model_name != 'None')
349
+
350
+ refiner_model.change(lambda x: gr.update(visible=x != 'None'),
351
+ inputs=refiner_model, outputs=refiner_switch, show_progress=False, queue=False)
352
+
353
+ with gr.Group():
354
+ lora_ctrls = []
355
+
356
+ for i, (n, v) in enumerate(modules.config.default_loras):
357
+ with gr.Row():
358
+ lora_enabled = gr.Checkbox(label='Enable', value=True,
359
+ elem_classes=['lora_enable', 'min_check'], scale=1)
360
+ lora_model = gr.Dropdown(label=f'LoRA {i + 1}',
361
+ choices=['None'] + modules.config.lora_filenames, value=n,
362
+ elem_classes='lora_model', scale=5)
363
+ lora_weight = gr.Slider(label='Weight', minimum=modules.config.default_loras_min_weight,
364
+ maximum=modules.config.default_loras_max_weight, step=0.01, value=v,
365
+ elem_classes='lora_weight', scale=5)
366
+ lora_ctrls += [lora_enabled, lora_model, lora_weight]
367
+
368
+ with gr.Row():
369
+ model_refresh = gr.Button(label='Refresh', value='\U0001f504 Refresh All Files', variant='secondary', elem_classes='refresh_button')
370
+ with gr.Tab(label='Advanced'):
371
+ guidance_scale = gr.Slider(label='Guidance Scale', minimum=1.0, maximum=30.0, step=0.01,
372
+ value=modules.config.default_cfg_scale,
373
+ info='Higher value means style is cleaner, vivider, and more artistic.')
374
+ sharpness = gr.Slider(label='Image Sharpness', minimum=0.0, maximum=30.0, step=0.001,
375
+ value=modules.config.default_sample_sharpness,
376
+ info='Higher value means image and texture are sharper.')
377
+ gr.HTML('<a href="https://github.com/lllyasviel/Fooocus/discussions/117" target="_blank">\U0001F4D4 Document</a>')
378
+ dev_mode = gr.Checkbox(label='Developer Debug Mode', value=False, container=False)
379
+
380
+ with gr.Column(visible=False) as dev_tools:
381
+ with gr.Tab(label='Debug Tools'):
382
+ adm_scaler_positive = gr.Slider(label='Positive ADM Guidance Scaler', minimum=0.1, maximum=3.0,
383
+ step=0.001, value=1.5, info='The scaler multiplied to positive ADM (use 1.0 to disable). ')
384
+ adm_scaler_negative = gr.Slider(label='Negative ADM Guidance Scaler', minimum=0.1, maximum=3.0,
385
+ step=0.001, value=0.8, info='The scaler multiplied to negative ADM (use 1.0 to disable). ')
386
+ adm_scaler_end = gr.Slider(label='ADM Guidance End At Step', minimum=0.0, maximum=1.0,
387
+ step=0.001, value=0.3,
388
+ info='When to end the guidance from positive/negative ADM. ')
389
+
390
+ refiner_swap_method = gr.Dropdown(label='Refiner swap method', value=flags.refiner_swap_method,
391
+ choices=['joint', 'separate', 'vae'])
392
+
393
+ adaptive_cfg = gr.Slider(label='CFG Mimicking from TSNR', minimum=1.0, maximum=30.0, step=0.01,
394
+ value=modules.config.default_cfg_tsnr,
395
+ info='Enabling Fooocus\'s implementation of CFG mimicking for TSNR '
396
+ '(effective when real CFG > mimicked CFG).')
397
+ sampler_name = gr.Dropdown(label='Sampler', choices=flags.sampler_list,
398
+ value=modules.config.default_sampler)
399
+ scheduler_name = gr.Dropdown(label='Scheduler', choices=flags.scheduler_list,
400
+ value=modules.config.default_scheduler)
401
+
402
+ generate_image_grid = gr.Checkbox(label='Generate Image Grid for Each Batch',
403
+ info='(Experimental) This may cause performance problems on some computers and certain internet conditions.',
404
+ value=False)
405
+
406
+ overwrite_step = gr.Slider(label='Forced Overwrite of Sampling Step',
407
+ minimum=-1, maximum=200, step=1,
408
+ value=modules.config.default_overwrite_step,
409
+ info='Set as -1 to disable. For developer debugging.')
410
+ overwrite_switch = gr.Slider(label='Forced Overwrite of Refiner Switch Step',
411
+ minimum=-1, maximum=200, step=1,
412
+ value=modules.config.default_overwrite_switch,
413
+ info='Set as -1 to disable. For developer debugging.')
414
+ overwrite_width = gr.Slider(label='Forced Overwrite of Generating Width',
415
+ minimum=-1, maximum=2048, step=1, value=-1,
416
+ info='Set as -1 to disable. For developer debugging. '
417
+ 'Results will be worse for non-standard numbers that SDXL is not trained on.')
418
+ overwrite_height = gr.Slider(label='Forced Overwrite of Generating Height',
419
+ minimum=-1, maximum=2048, step=1, value=-1,
420
+ info='Set as -1 to disable. For developer debugging. '
421
+ 'Results will be worse for non-standard numbers that SDXL is not trained on.')
422
+ overwrite_vary_strength = gr.Slider(label='Forced Overwrite of Denoising Strength of "Vary"',
423
+ minimum=-1, maximum=1.0, step=0.001, value=-1,
424
+ info='Set as negative number to disable. For developer debugging.')
425
+ overwrite_upscale_strength = gr.Slider(label='Forced Overwrite of Denoising Strength of "Upscale"',
426
+ minimum=-1, maximum=1.0, step=0.001, value=-1,
427
+ info='Set as negative number to disable. For developer debugging.')
428
+ disable_preview = gr.Checkbox(label='Disable Preview', value=False,
429
+ info='Disable preview during generation.')
430
+ disable_intermediate_results = gr.Checkbox(label='Disable Intermediate Results',
431
+ value=modules.config.default_performance == 'Extreme Speed',
432
+ interactive=modules.config.default_performance != 'Extreme Speed',
433
+ info='Disable intermediate results during generation, only show final gallery.')
434
+ disable_seed_increment = gr.Checkbox(label='Disable seed increment',
435
+ info='Disable automatic seed increment when image number is > 1.',
436
+ value=False)
437
+
438
+ if not args_manager.args.disable_metadata:
439
+ save_metadata_to_images = gr.Checkbox(label='Save Metadata to Images', value=modules.config.default_save_metadata_to_images,
440
+ info='Adds parameters to generated images allowing manual regeneration.')
441
+ metadata_scheme = gr.Radio(label='Metadata Scheme', choices=flags.metadata_scheme, value=modules.config.default_metadata_scheme,
442
+ info='Image Prompt parameters are not included. Use png and a1111 for compatibility with Civitai.',
443
+ visible=modules.config.default_save_metadata_to_images)
444
+
445
+ save_metadata_to_images.change(lambda x: gr.update(visible=x), inputs=[save_metadata_to_images], outputs=[metadata_scheme],
446
+ queue=False, show_progress=False)
447
+
448
+ with gr.Tab(label='Control'):
449
+ debugging_cn_preprocessor = gr.Checkbox(label='Debug Preprocessors', value=False,
450
+ info='See the results from preprocessors.')
451
+ skipping_cn_preprocessor = gr.Checkbox(label='Skip Preprocessors', value=False,
452
+ info='Do not preprocess images. (Inputs are already canny/depth/cropped-face/etc.)')
453
+
454
+ mixing_image_prompt_and_vary_upscale = gr.Checkbox(label='Mixing Image Prompt and Vary/Upscale',
455
+ value=False)
456
+ mixing_image_prompt_and_inpaint = gr.Checkbox(label='Mixing Image Prompt and Inpaint',
457
+ value=False)
458
+
459
+ controlnet_softness = gr.Slider(label='Softness of ControlNet', minimum=0.0, maximum=1.0,
460
+ step=0.001, value=0.25,
461
+ info='Similar to the Control Mode in A1111 (use 0.0 to disable). ')
462
+
463
+ with gr.Tab(label='Canny'):
464
+ canny_low_threshold = gr.Slider(label='Canny Low Threshold', minimum=1, maximum=255,
465
+ step=1, value=64)
466
+ canny_high_threshold = gr.Slider(label='Canny High Threshold', minimum=1, maximum=255,
467
+ step=1, value=128)
468
+
469
+ with gr.Tab(label='Inpaint'):
470
+ debugging_inpaint_preprocessor = gr.Checkbox(label='Debug Inpaint Preprocessing', value=False)
471
+ inpaint_disable_initial_latent = gr.Checkbox(label='Disable initial latent in inpaint', value=False)
472
+ inpaint_engine = gr.Dropdown(label='Inpaint Engine',
473
+ value=modules.config.default_inpaint_engine_version,
474
+ choices=flags.inpaint_engine_versions,
475
+ info='Version of Fooocus inpaint model')
476
+ inpaint_strength = gr.Slider(label='Inpaint Denoising Strength',
477
+ minimum=0.0, maximum=1.0, step=0.001, value=1.0,
478
+ info='Same as the denoising strength in A1111 inpaint. '
479
+ 'Only used in inpaint, not used in outpaint. '
480
+ '(Outpaint always use 1.0)')
481
+ inpaint_respective_field = gr.Slider(label='Inpaint Respective Field',
482
+ minimum=0.0, maximum=1.0, step=0.001, value=0.618,
483
+ info='The area to inpaint. '
484
+ 'Value 0 is same as "Only Masked" in A1111. '
485
+ 'Value 1 is same as "Whole Image" in A1111. '
486
+ 'Only used in inpaint, not used in outpaint. '
487
+ '(Outpaint always use 1.0)')
488
+ inpaint_erode_or_dilate = gr.Slider(label='Mask Erode or Dilate',
489
+ minimum=-64, maximum=64, step=1, value=0,
490
+ info='Positive value will make white area in the mask larger, '
491
+ 'negative value will make white area smaller.'
492
+ '(default is 0, always process before any mask invert)')
493
+ inpaint_mask_upload_checkbox = gr.Checkbox(label='Enable Mask Upload', value=False)
494
+ invert_mask_checkbox = gr.Checkbox(label='Invert Mask', value=False)
495
+
496
+ inpaint_ctrls = [debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine,
497
+ inpaint_strength, inpaint_respective_field,
498
+ inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate]
499
+
500
+ inpaint_mask_upload_checkbox.change(lambda x: gr.update(visible=x),
501
+ inputs=inpaint_mask_upload_checkbox,
502
+ outputs=inpaint_mask_image, queue=False, show_progress=False)
503
+
504
+ with gr.Tab(label='FreeU'):
505
+ freeu_enabled = gr.Checkbox(label='Enabled', value=False)
506
+ freeu_b1 = gr.Slider(label='B1', minimum=0, maximum=2, step=0.01, value=1.01)
507
+ freeu_b2 = gr.Slider(label='B2', minimum=0, maximum=2, step=0.01, value=1.02)
508
+ freeu_s1 = gr.Slider(label='S1', minimum=0, maximum=4, step=0.01, value=0.99)
509
+ freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95)
510
+ freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2]
511
+
512
+ def dev_mode_checked(r):
513
+ return gr.update(visible=r)
514
+
515
+
516
+ dev_mode.change(dev_mode_checked, inputs=[dev_mode], outputs=[dev_tools],
517
+ queue=False, show_progress=False)
518
+
519
+ def model_refresh_clicked():
520
+ modules.config.update_all_model_names()
521
+ results = [gr.update(choices=modules.config.model_filenames)]
522
+ results += [gr.update(choices=['None'] + modules.config.model_filenames)]
523
+ for i in range(modules.config.default_max_lora_number):
524
+ results += [gr.update(interactive=True), gr.update(choices=['None'] + modules.config.lora_filenames), gr.update()]
525
+ return results
526
+
527
+ model_refresh.click(model_refresh_clicked, [], [base_model, refiner_model] + lora_ctrls,
528
+ queue=False, show_progress=False)
529
+
530
+ performance_selection.change(lambda x: [gr.update(interactive=x != 'Extreme Speed')] * 11 +
531
+ [gr.update(visible=x != 'Extreme Speed')] * 1 +
532
+ [gr.update(interactive=x != 'Extreme Speed', value=x == 'Extreme Speed', )] * 1,
533
+ inputs=performance_selection,
534
+ outputs=[
535
+ guidance_scale, sharpness, adm_scaler_end, adm_scaler_positive,
536
+ adm_scaler_negative, refiner_switch, refiner_model, sampler_name,
537
+ scheduler_name, adaptive_cfg, refiner_swap_method, negative_prompt, disable_intermediate_results
538
+ ], queue=False, show_progress=False)
539
+
540
+ output_format.input(lambda x: gr.update(output_format=x), inputs=output_format)
541
+
542
+ advanced_checkbox.change(lambda x: gr.update(visible=x), advanced_checkbox, advanced_column,
543
+ queue=False, show_progress=False) \
544
+ .then(fn=lambda: None, _js='refresh_grid_delayed', queue=False, show_progress=False)
545
+
546
+ def inpaint_mode_change(mode):
547
+ assert mode in modules.flags.inpaint_options
548
+
549
+ # inpaint_additional_prompt, outpaint_selections, example_inpaint_prompts,
550
+ # inpaint_disable_initial_latent, inpaint_engine,
551
+ # inpaint_strength, inpaint_respective_field
552
+
553
+ if mode == modules.flags.inpaint_option_detail:
554
+ return [
555
+ gr.update(visible=True), gr.update(visible=False, value=[]),
556
+ gr.Dataset.update(visible=True, samples=modules.config.example_inpaint_prompts),
557
+ False, 'None', 0.5, 0.0
558
+ ]
559
+
560
+ if mode == modules.flags.inpaint_option_modify:
561
+ return [
562
+ gr.update(visible=True), gr.update(visible=False, value=[]),
563
+ gr.Dataset.update(visible=False, samples=modules.config.example_inpaint_prompts),
564
+ True, modules.config.default_inpaint_engine_version, 1.0, 0.0
565
+ ]
566
+
567
+ return [
568
+ gr.update(visible=False, value=''), gr.update(visible=True),
569
+ gr.Dataset.update(visible=False, samples=modules.config.example_inpaint_prompts),
570
+ False, modules.config.default_inpaint_engine_version, 1.0, 0.618
571
+ ]
572
+
573
+ inpaint_mode.input(inpaint_mode_change, inputs=inpaint_mode, outputs=[
574
+ inpaint_additional_prompt, outpaint_selections, example_inpaint_prompts,
575
+ inpaint_disable_initial_latent, inpaint_engine,
576
+ inpaint_strength, inpaint_respective_field
577
+ ], show_progress=False, queue=False)
578
 
579
+ ctrls = [currentTask, generate_image_grid]
580
+ ctrls += [
581
+ prompt, negative_prompt, style_selections,
582
+ performance_selection, aspect_ratios_selection, image_number, output_format, image_seed, sharpness, guidance_scale
583
+ ]
584
+
585
+ ctrls += [base_model, refiner_model, refiner_switch] + lora_ctrls
586
+ ctrls += [input_image_checkbox, current_tab]
587
+ ctrls += [uov_method, uov_input_image]
588
+ ctrls += [outpaint_selections, inpaint_input_image, inpaint_additional_prompt, inpaint_mask_image]
589
+ ctrls += [disable_preview, disable_intermediate_results, disable_seed_increment]
590
+ ctrls += [adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg]
591
+ ctrls += [sampler_name, scheduler_name]
592
+ ctrls += [overwrite_step, overwrite_switch, overwrite_width, overwrite_height, overwrite_vary_strength]
593
+ ctrls += [overwrite_upscale_strength, mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint]
594
+ ctrls += [debugging_cn_preprocessor, skipping_cn_preprocessor, canny_low_threshold, canny_high_threshold]
595
+ ctrls += [refiner_swap_method, controlnet_softness]
596
+ ctrls += freeu_ctrls
597
+ ctrls += inpaint_ctrls
598
+
599
+ if not args_manager.args.disable_metadata:
600
+ ctrls += [save_metadata_to_images, metadata_scheme]
601
+
602
+ ctrls += ip_ctrls
603
+
604
+ state_is_generating = gr.State(False)
605
+
606
+ def parse_meta(raw_prompt_txt, is_generating):
607
+ loaded_json = None
608
+ if is_json(raw_prompt_txt):
609
+ loaded_json = json.loads(raw_prompt_txt)
610
+
611
+ if loaded_json is None:
612
+ if is_generating:
613
+ return gr.update(), gr.update(), gr.update()
614
+ else:
615
+ return gr.update(), gr.update(visible=True), gr.update(visible=False)
616
+
617
+ return json.dumps(loaded_json), gr.update(visible=False), gr.update(visible=True)
618
+
619
+ prompt.input(parse_meta, inputs=[prompt, state_is_generating], outputs=[prompt, generate_button, load_parameter_button], queue=False, show_progress=False)
620
+
621
+ load_data_outputs = [advanced_checkbox, image_number, prompt, negative_prompt, style_selections,
622
+ performance_selection, overwrite_step, overwrite_switch, aspect_ratios_selection,
623
+ overwrite_width, overwrite_height, guidance_scale, sharpness, adm_scaler_positive,
624
+ adm_scaler_negative, adm_scaler_end, refiner_swap_method, adaptive_cfg, base_model,
625
+ refiner_model, refiner_switch, sampler_name, scheduler_name, seed_random, image_seed,
626
+ generate_button, load_parameter_button] + freeu_ctrls + lora_ctrls
627
+
628
+ load_parameter_button.click(modules.meta_parser.load_parameter_button_click, inputs=[prompt, state_is_generating], outputs=load_data_outputs, queue=False, show_progress=False)
629
+
630
+ def trigger_metadata_import(filepath, state_is_generating):
631
+ parameters, metadata_scheme = modules.meta_parser.read_info_from_image(filepath)
632
+ if parameters is None:
633
+ print('Could not find metadata in the image!')
634
+ parsed_parameters = {}
635
+ else:
636
+ metadata_parser = modules.meta_parser.get_metadata_parser(metadata_scheme)
637
+ parsed_parameters = metadata_parser.parse_json(parameters)
638
+
639
+ return modules.meta_parser.load_parameter_button_click(parsed_parameters, state_is_generating)
640
+
641
+
642
+ metadata_import_button.click(trigger_metadata_import, inputs=[metadata_input_image, state_is_generating], outputs=load_data_outputs, queue=False, show_progress=True) \
643
+ .then(style_sorter.sort_styles, inputs=style_selections, outputs=style_selections, queue=False, show_progress=False)
644
+
645
+ generate_button.click(lambda: (gr.update(visible=True, interactive=True), gr.update(visible=True, interactive=True), gr.update(visible=False, interactive=False), [], True),
646
+ outputs=[stop_button, skip_button, generate_button, gallery, state_is_generating]) \
647
+ .then(fn=refresh_seed, inputs=[seed_random, image_seed], outputs=image_seed) \
648
+ .then(fn=get_task, inputs=ctrls, outputs=currentTask) \
649
+ .then(fn=generate_clicked, inputs=currentTask, outputs=[progress_html, progress_window, progress_gallery, gallery]) \
650
+ .then(lambda: (gr.update(visible=True, interactive=True), gr.update(visible=False, interactive=False), gr.update(visible=False, interactive=False), False),
651
+ outputs=[generate_button, stop_button, skip_button, state_is_generating]) \
652
+ .then(fn=update_history_link, outputs=history_link) \
653
+ .then(fn=lambda: None, _js='playNotification').then(fn=lambda: None, _js='refresh_grid_delayed')
654
+
655
+ for notification_file in ['notification.ogg', 'notification.mp3']:
656
+ if os.path.exists(notification_file):
657
+ gr.Audio(interactive=False, value=notification_file, elem_id='audio_notification', visible=False)
658
+ break
659
+
660
+ def trigger_describe(mode, img):
661
+ if mode == flags.desc_type_photo:
662
+ from extras.interrogate import default_interrogator as default_interrogator_photo
663
+ return default_interrogator_photo(img), ["Fooocus V2", "Fooocus Enhance", "Fooocus Sharp"]
664
+ if mode == flags.desc_type_anime:
665
+ from extras.wd14tagger import default_interrogator as default_interrogator_anime
666
+ return default_interrogator_anime(img), ["Fooocus V2", "Fooocus Masterpiece"]
667
+ return mode, ["Fooocus V2"]
668
+
669
+ desc_btn.click(trigger_describe, inputs=[desc_method, desc_input_image],
670
+ outputs=[prompt, style_selections], show_progress=True, queue=True)
671
+
672
+
673
+ def dump_default_english_config():
674
+ from modules.localization import dump_english_config
675
+ dump_english_config(grh.all_components)
676
+
677
+
678
+ # dump_default_english_config()
679
+ interface = Interface(
680
+ fn=None, # Replace None with the function that defines your Gradio interface
681
+ inbrowser=args_manager.args.in_browser,
682
+ server_name=args_manager.args.listen,
683
+ server_port=args_manager.args.port,
684
+ share=args_manager.args.share,
685
+ auth=check_auth if (args_manager.args.share or args_manager.args.listen) and auth_enabled else None,
686
+ allowed_paths=[modules.config.path_outputs],
687
+ blocked_paths=[constants.AUTH_FILENAME]
688
+ )
689
+
690
+ interface.launch()
691
+ import gradio as gr
692
+ import random
693
+ import os
694
+ import json
695
+ import time
696
+ import shared
697
+ import modules.config
698
+ import fooocus_version
699
+ import modules.html
700
+ import modules.async_worker as worker
701
+ import modules.constants as constants
702
+ import modules.flags as flags
703
+ import modules.gradio_hijack as grh
704
+ import modules.style_sorter as style_sorter
705
+ import modules.meta_parser
706
+ import args_manager
707
+ import copy
708
+ from gradio import Interface
709
  from modules.sdxl_styles import legal_style_names
710
  from modules.private_logger import get_current_html_path
711
  from modules.ui_gradio_extensions import reload_javascript
712
  from modules.auth import auth_enabled, check_auth
713
  from modules.util import is_json
714
+
715
  def get_task(*args):
716
  args = list(args)
717
  args.pop(0)
 
1365
  dump_english_config(grh.all_components)
1366
 
1367
 
1368
+ # dump_default_english_config()
1369
+ interface = Interface(
1370
+ fn=None, # Replace None with the function that defines your Gradio interface
1371
  inbrowser=args_manager.args.in_browser,
1372
  server_name=args_manager.args.listen,
1373
  server_port=args_manager.args.port,
 
1376
  allowed_paths=[modules.config.path_outputs],
1377
  blocked_paths=[constants.AUTH_FILENAME]
1378
  )
1379
+
1380
+ interface.launch()