Skip to content

Commit 875c9b2

Browse files
authored
Merge pull request #399 from mrhan1993/dev
Update Fooocus to 2.5.3
2 parents efc73d0 + c64d672 commit 875c9b2

File tree

121 files changed

+43392
-1839
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+43392
-1839
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ config.txt
3434
config_modification_tutorial.txt
3535
user_path_config.txt
3636
user_path_config-deprecated.txt
37+
hash_cache.txt
3738

3839
sorted_styles.json
3940
/presets

README.md

+55-6
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,65 @@
1919
- [License](#license)
2020
- [Thanks :purple\_heart:](#thanks-purple_heart)
2121

22-
If this is the first time to use it, it is recommended to use a rewritten new project [FooocusAPI](https://github.com/mrhan1993/FooocusAPI)
22+
> Note:
23+
>
24+
> Fooocus 2.5 includes a significant update, with most dependencies upgraded. Therefore, after updating, do not use `--skip-pip` unless you have already performed a manual update.
25+
>
26+
> Additionally, `groundingdino-py` may encounter installation errors, especially in Chinese Windows environments. The solution can be found in the following [issue](https://github.com/IDEA-Research/GroundingDINO/issues/206).
27+
28+
29+
> GenerateMask is same as DescribeImage, It is not process as a task, result will directly return
30+
31+
# Instructions for Using the ImageEnhance Interface
32+
Below are examples of parameters that include the main parameters required for ImageEnhance. The V1 interface adopts a form-like approach similar to ImagePrompt to break down the enhance controller.
33+
34+
35+
```python
36+
{
37+
"enhance_input_image": "",
38+
"enhance_checkbox": true,
39+
"enhance_uov_method": "Vary (Strong)",
40+
"enhance_uov_processing_order": "Before First Enhancement",
41+
"enhance_uov_prompt_type": "Original Prompts",
42+
"save_final_enhanced_image_only": true,
43+
"enhance_ctrlnets": [
44+
{
45+
"enhance_enabled": false,
46+
"enhance_mask_dino_prompt": "face",
47+
"enhance_prompt": "",
48+
"enhance_negative_prompt": "",
49+
"enhance_mask_model": "sam",
50+
"enhance_mask_cloth_category": "full",
51+
"enhance_mask_sam_model": "vit_b",
52+
"enhance_mask_text_threshold": 0.25,
53+
"enhance_mask_box_threshold": 0.3,
54+
"enhance_mask_sam_max_detections": 0,
55+
"enhance_inpaint_disable_initial_latent": false,
56+
"enhance_inpaint_engine": "v2.6",
57+
"enhance_inpaint_strength": 1,
58+
"enhance_inpaint_respective_field": 0.618,
59+
"enhance_inpaint_erode_or_dilate": 0,
60+
"enhance_mask_invert": false
61+
}
62+
]
63+
}
64+
```
65+
66+
- enhance_input_image: The image to be enhanced, which is required and can be provided as an image URL for the V2 interface.
67+
- enhance_checkbox: A toggle switch that must be set to true if you want to use the enhance image feature.
68+
- save_final_enhanced_image_only: Since image enhancement is a pipeline operation, it can produce multiple result images. This parameter allows you to only return the final enhanced image.
69+
70+
There are three parameters related to UpscaleVary, which are used to perform Upscale or Vary before or after enhancement.
2371

24-
A migration guide is provided [here](./docs/migrate.md).
72+
- enhance_uov_method: Similar to the UpscaleOrVary interface, Disabled turns it off.
73+
- enhance_uov_processing_order: Determines whether to process the image before or after enhancement.
74+
- enhance_uov_prompt_type: I'm not sure about the specific function; you might want to research it based on the WebUI.
2575

26-
# :warning: Compatibility warning :warning:
76+
The `enhance_ctrlnets` element is a list of ImageEnhance controller objects, with a maximum of three elements in the list, any additional elements will be discarded. The parameters correspond roughly to the WebUI, and the notable parameters are:
2777

28-
When upgrading from version 3.x to version 4.0, please read the following incompatibility notes:
78+
- enhance_enabled: This parameter controls whether the enhance controller is active. If there are no enabled enhance controllers, the task will be skipped.
79+
- enhance_mask_dino_prompt: This parameter is required and indicates the area to be enhanced. If it is empty, even if the enhance controller is enabled, the task will be skipped.
2980

30-
1. If you are using an external Fooocus model (that is, the model is not located in the `repositories` directory), delete the `repositories` directory directly, and then update the `git pull`.
31-
2. If not, move the `repositories` directory to any directory, delete the `repositories` directory, then update the `git pull`, and move the `models` directory back to its original location when it is finished.
3281

3382
# Introduction
3483

README_zh.md

+55-7
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,70 @@
1919
- [License](#license)
2020
- [感谢 :purple\_heart:](#感谢-purple_heart)
2121

22-
如果是第一次使用,推荐使用重写后的新项目 [FooocusAPI](https://github.com/mrhan1993/FooocusAPI)
2322

24-
我还准备了一个[迁移指南](./docs/migrate_zh.md)
23+
> 注意:
24+
>
25+
> Fooocus 2.5 包含大量更新,其中多数依赖进行了升级,因此,更新后请不要使用 `--skip-pip`. 除非你已经进行过手动更新
26+
>
27+
> 此外, `groundingdino-py` 可能会遇到安装错误, 特别是在中文 windows 环境中, 解决办法参考: [issues](https://github.com/IDEA-Research/GroundingDINO/issues/206)
28+
29+
> 和 DescribeImage 一样,GenerateMask 不会作为 task 处理而是直接返回结果
30+
31+
# ImageEnhance 接口的使用说明
32+
33+
以下面的参数为例,它包含了 ImageEnhance 所需要的主要参数,V1 接口采用和 ImagePrompt 类似的方式将 enhance 控制器拆分成表单形式:
34+
35+
```python
36+
{
37+
"enhance_input_image": "",
38+
"enhance_checkbox": true,
39+
"enhance_uov_method": "Vary (Strong)",
40+
"enhance_uov_processing_order": "Before First Enhancement",
41+
"enhance_uov_prompt_type": "Original Prompts",
42+
"save_final_enhanced_image_only": true,
43+
"enhance_ctrlnets": [
44+
{
45+
"enhance_enabled": false,
46+
"enhance_mask_dino_prompt": "face",
47+
"enhance_prompt": "",
48+
"enhance_negative_prompt": "",
49+
"enhance_mask_model": "sam",
50+
"enhance_mask_cloth_category": "full",
51+
"enhance_mask_sam_model": "vit_b",
52+
"enhance_mask_text_threshold": 0.25,
53+
"enhance_mask_box_threshold": 0.3,
54+
"enhance_mask_sam_max_detections": 0,
55+
"enhance_inpaint_disable_initial_latent": false,
56+
"enhance_inpaint_engine": "v2.6",
57+
"enhance_inpaint_strength": 1,
58+
"enhance_inpaint_respective_field": 0.618,
59+
"enhance_inpaint_erode_or_dilate": 0,
60+
"enhance_mask_invert": false
61+
}
62+
]
63+
}
64+
```
65+
66+
- enhance_input_image:需要增强的图像,如果是 v2 接口,可以提供一个图像 url,必选
67+
- enhance_checkbox:总开关,使用 enhance image 必须设置为 true
68+
- save_final_enhanced_image_only:图像增强是一个管道作业,因此会产生多个结果图像,使用该参数仅返回最终图像
69+
70+
有三个和 UpscaleVary 相关的参数,其作用是执行增强之前或完成增强之后执行 Upscale 或 Vary
2571

26-
# :warning: 兼容性警告 :warning:
72+
- enhance_uov_method:和 UpscaleOrVary 接口一样,Disabled 是关闭
73+
- enhance_uov_processing_order:在增强之前处理还是处理增强后的图像
74+
- enhance_uov_prompt_type:我也不知道具体作用,对着 WebUI 研究研究🧐
2775

28-
如果是从 0.3.x 版本升级到 0.4.0 版本,请务必阅读以下兼容性说明
76+
`enhance_ctrlnets` 元素为 ImageEnhance 控制器对象列表,该列表最多包含 3 个元素,多余会被丢弃。参数和 WebUI 基本一一对应,需要注意的参数是
2977

30-
1. 如果你使用的是外部 Fooocus 模型(即模型不是位于 `repositories/Fooocus/models` 目录下),直接删除 `repositories` 目录,然后执行 `git pull` 更新即可
31-
2. 如果不是上述方式,将 `repositories/Fooocus/models` 目录移动到任意目录,删除 `repositories` 目录,然后执行 `git pull` 更新,完成后将 `models` 目录移动回原位置
78+
- enhance_enabled:参数控制该 enhance 控制器是否工作,如果没有开启的 enhance 控制器,任务会被跳过
79+
- enhance_mask_dino_prompt:该参数必选,表示需要增强的部位,如果该参数为空,即便 enhance 控制器处于开启状态,也会跳过
3280

3381
# 简介
3482

3583
使用 FastAPI 构建的 [Fooocus](https://github.com/lllyasviel/Fooocus) 的 API。
3684

37-
当前支持的 Fooocus 版本: [2.3.1](https://github.com/lllyasviel/Fooocus/blob/main/update_log.md)
85+
当前支持的 Fooocus 版本: [2.5.3](https://github.com/lllyasviel/Fooocus/blob/main/update_log.md)
3886

3987
## Fooocus
4088

docs/change_logs.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# ChangeLog for Fooocus-API
22

3-
## [UNRELEASE]
3+
## [v0.5.0.1]
44
### Changed
5+
- Fooocus to v2.5.3
6+
- Add enhance image endpoint
7+
- Add generate mask endpoint
8+
- Influenced by Fooocus, the worker.py was reconstructed
59
- Update docs
6-
- Returnd base64 str now include identifier like this `data:image/jpeg;base64,`
10+
- Returned base64 str now include identifier like this `data:image/jpeg;base64,`
711

812
### Fixed
913
- Issue #375

docs/change_logs_zh.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# ChangeLog for Fooocus-API
22

3-
## [UNRELEASE]
3+
## [v0.5.0.1]
44
### Changed
5+
- 合并到 Fooocus 2.5.3
6+
- 增加图像增强接口
7+
- 增加遮罩生成接口
8+
- 受 Fooocus 影响,重构了 worker.py
59
- 更新文档
610
- 返回数据中的 base64 字符串现在包含图像标识符,比如 `data:image/jpeg;base64,`
711

examples/examples.ipynb

+6-15
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,14 @@
99
},
1010
{
1111
"cell_type": "code",
12-
"execution_count": 8,
12+
"execution_count": null,
1313
"metadata": {
1414
"ExecuteTime": {
1515
"end_time": "2024-04-04T10:19:57.369099Z",
1616
"start_time": "2024-04-04T10:19:57.328298Z"
1717
}
1818
},
19-
"outputs": [
20-
{
21-
"name": "stdout",
22-
"output_type": "stream",
23-
"text": [
24-
"{'job_id': 'b53d8776-62a6-4398-bb8f-8118dc57403a', 'job_type': 'Text to Image', 'job_stage': 'WAITING', 'job_progress': 0, 'job_status': None, 'job_step_preview': None, 'job_result': None}\n"
25-
]
26-
}
27-
],
19+
"outputs": [],
2820
"source": [
2921
"import requests\n",
3022
"import json\n",
@@ -43,7 +35,6 @@
4335
" return response.json()\n",
4436
"\n",
4537
"result =text2img({\n",
46-
" \"prompt\": \"1girl sitting on the ground\",\n",
4738
" \"performance_selection\": \"Lightning\",\n",
4839
" \"async_process\": True\n",
4940
"})\n",
@@ -84,7 +75,7 @@
8475
"result =upscale_vary(\n",
8576
" image=image,\n",
8677
" params={\n",
87-
" \"uov_method\": \"Upscale (2x)\",\n",
78+
" \"uov_method\": \"Vary\",\n",
8879
" \"async_process\": True\n",
8980
" })\n",
9081
"print(json.dumps(result, indent=4, ensure_ascii=False))"
@@ -352,8 +343,8 @@
352343
"# image_prompt v2 Interface example\n",
353344
"host = \"http://127.0.0.1:8888\"\n",
354345
"image = open(\"./imgs/bear.jpg\", \"rb\").read()\n",
355-
"source = open(\"./imgs/s.jpg\", \"rb\").read()\n",
356-
"mask = open(\"./imgs/m.png\", \"rb\").read()\n",
346+
"source = open(\"./imgs/inpaint_source.jpg\", \"rb\").read()\n",
347+
"mask = open(\"./imgs/inpaint_mask.png\", \"rb\").read()\n",
357348
"\n",
358349
"def image_prompt(params: dict) -> dict:\n",
359350
" \"\"\"\n",
@@ -522,7 +513,7 @@
522513
"name": "python",
523514
"nbconvert_exporter": "python",
524515
"pygments_lexer": "ipython3",
525-
"version": "3.10.10"
516+
"version": "3.10.13"
526517
}
527518
},
528519
"nbformat": 4,

examples/examples_v1.py

+36
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,39 @@ def image_prompt(
228228
cn_img2=ImageList.image_prompt_1,
229229
)
230230
print(json.dumps(ip_result))
231+
232+
# ###############################################################
233+
# Image Enhance
234+
# ################################################################
235+
236+
# Image Enhance
237+
238+
import requests
239+
240+
url = "http://localhost:8888/v1/generation/image-enhance"
241+
242+
# Define the file path and other form data
243+
file_path = "./examples/imgs/source_face_man.png"
244+
form_data = {
245+
"enhance_checkbox": True,
246+
"enhance_uov_method": "Disabled",
247+
"enhance_enabled_1": True,
248+
"enhance_mask_dino_prompt_1": "face",
249+
"enhance_enabled_2": True,
250+
"enhance_mask_dino_prompt_2": "eyes",
251+
}
252+
253+
# Open the file and prepare it for the request
254+
with open(file_path, "rb") as f:
255+
image = f.read()
256+
f.close()
257+
258+
# Send the request
259+
response = requests.post(
260+
url,
261+
files={"enhance_input_image": image},
262+
data=form_data,
263+
timeout=180)
264+
265+
# Print the response content
266+
print(response.text)

examples/examples_v2.py

+56
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,59 @@ def text2image_image_prompt(params: dict) -> dict:
230230

231231
t2i_ip_result = text2image_image_prompt(params=t2i_ip_params)
232232
print(json.dumps(t2i_ip_result))
233+
234+
# ################################################################
235+
# Image Enhance
236+
# ################################################################
237+
238+
# Image Enhance
239+
240+
import requests
241+
import json
242+
243+
url = "http://localhost:8888/v2/generation/image-enhance"
244+
245+
headers = {
246+
"Content-Type": "application/json"
247+
}
248+
249+
data = {
250+
"enhance_input_image": "https://raw.githubusercontent.com/mrhan1993/Fooocus-API/main/examples/imgs/source_face_man.png",
251+
"enhance_checkbox": True,
252+
"enhance_uov_method": "Vary (Strong)",
253+
"enhance_uov_processing_order": "Before First Enhancement",
254+
"enhance_uov_prompt_type": "Original Prompts",
255+
"enhance_ctrlnets": [
256+
{
257+
"enhance_enabled": True,
258+
"enhance_mask_dino_prompt": "face",
259+
"enhance_prompt": "",
260+
"enhance_negative_prompt": "",
261+
"enhance_mask_model": "sam",
262+
"enhance_mask_cloth_category": "full",
263+
"enhance_mask_sam_model": "vit_b",
264+
"enhance_mask_text_threshold": 0.25,
265+
"enhance_mask_box_threshold": 0.3,
266+
"enhance_mask_sam_max_detections": 0,
267+
"enhance_inpaint_disable_initial_latent": False,
268+
"enhance_inpaint_engine": "v2.6",
269+
"enhance_inpaint_strength": 1.0,
270+
"enhance_inpaint_respective_field": 0.618,
271+
"enhance_inpaint_erode_or_dilate": 0.0,
272+
"enhance_mask_invert": False
273+
}
274+
]
275+
}
276+
277+
response = requests.post(
278+
url,
279+
headers=headers,
280+
data=json.dumps(data),
281+
timeout=180)
282+
283+
if response.status_code == 200:
284+
print("Request successful!")
285+
print("Response:", response.json())
286+
else:
287+
print("Request failed with status code:", response.status_code)
288+
print("Response:", response.text)

extras/BLIP/configs/bert_config.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"architectures": [
3+
"BertModel"
4+
],
5+
"attention_probs_dropout_prob": 0.1,
6+
"hidden_act": "gelu",
7+
"hidden_dropout_prob": 0.1,
8+
"hidden_size": 768,
9+
"initializer_range": 0.02,
10+
"intermediate_size": 3072,
11+
"layer_norm_eps": 1e-12,
12+
"max_position_embeddings": 512,
13+
"model_type": "bert",
14+
"num_attention_heads": 12,
15+
"num_hidden_layers": 12,
16+
"pad_token_id": 0,
17+
"type_vocab_size": 2,
18+
"vocab_size": 30522,
19+
"encoder_width": 768,
20+
"add_cross_attention": true
21+
}

0 commit comments

Comments
 (0)