Skip to content

Commit

Permalink
Merge pull request #148 from konieshadow/dev
Browse files Browse the repository at this point in the history
v0.3.29 Merged Fooocus v2.1.860
  • Loading branch information
konieshadow authored Jan 4, 2024
2 parents 8872939 + ea74ed8 commit 3601658
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 20 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

FastAPI powered API for [Fooocus](https://github.com/lllyasviel/Fooocus).

Currently loaded Fooocus version: [2.1.852](https://github.com/lllyasviel/Fooocus/blob/main/update_log.md).
Currently loaded Fooocus version: [2.1.860](https://github.com/lllyasviel/Fooocus/blob/main/update_log.md).

## Fooocus

Expand Down Expand Up @@ -194,6 +194,8 @@ For Fooocus CMD flags, see [here](https://github.com/lllyasviel/Fooocus?tab=read

# Change log

**[24/01/04] v0.3.29** : Merged Fooocus v2.1.860

**[24/01/03] v0.3.28** : add text-to-image-with-ip interface

**[23/12/29] v0.3.27** : Add describe interface,now you can get prompt from image
Expand Down
4 changes: 3 additions & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

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

当前支持的 Fooocus 版本: [2.1.852](https://github.com/lllyasviel/Fooocus/blob/main/update_log.md)
当前支持的 Fooocus 版本: [2.1.860](https://github.com/lllyasviel/Fooocus/blob/main/update_log.md)

## Fooocus

Expand Down Expand Up @@ -194,6 +194,8 @@ python main.py --all-in-fp16 --always-gpu

# 更新日志

**[24/01/04] v0.3.29** : 合并了 Fooocus v2.1.860

**[24/01/03] v0.3.28** : 增加 text-to-image-with-ip 接口

**[23/12/29] v0.3.27** : 增加 describe 接口,现在你可以使用图像反推提示词了
Expand Down
2 changes: 1 addition & 1 deletion docs/api_doc_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ DataType: form

| Name | Type | Description |
|------|------|------------------------------------------|
| type | Enum | type, should be one of "Photo", "Animd" |
| type | Enum | type, should be one of "Photo", "Anime" |

**requests example**:

Expand Down
2 changes: 1 addition & 1 deletion docs/api_doc_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ DataType: form

| Name | Type | Description |
|------|------|-----------------------------|
| type | Enum | 反推类型, "Photo", "Animd" 中的一个 |
| type | Enum | 反推类型, "Photo", "Anime" 中的一个 |

**请求示例**:

Expand Down
2 changes: 1 addition & 1 deletion docs/openapi.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion fooocus_api_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = '0.3.28'
version = '0.3.29'
3 changes: 2 additions & 1 deletion fooocusapi/api_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ def req_to_params(req: Text2ImgRequest) -> ImageGenerationParams:
adp.debugging_cn_preprocessor, adp.skipping_cn_preprocessor, adp.controlnet_softness, adp.canny_low_threshold, adp.canny_high_threshold, \
adp.refiner_swap_method, \
adp.freeu_enabled, adp.freeu_b1, adp.freeu_b2, adp.freeu_s1, adp.freeu_s2, \
adp.debugging_inpaint_preprocessor, adp.inpaint_disable_initial_latent, adp.inpaint_engine, adp.inpaint_strength, adp.inpaint_respective_field
adp.debugging_inpaint_preprocessor, adp.inpaint_disable_initial_latent, adp.inpaint_engine, adp.inpaint_strength, adp.inpaint_respective_field, \
False, adp.invert_mask_checkbox, adp.inpaint_erode_or_dilate
]

return ImageGenerationParams(prompt=prompt,
Expand Down
2 changes: 2 additions & 0 deletions fooocusapi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class AdvancedParams(BaseModel):
inpaint_engine: str = Field('v1', description="Inpaint Engine")
inpaint_strength: float = Field(1.0, description="Inpaint Denoising Strength", ge=0.0, le=1.0)
inpaint_respective_field: float = Field(1.0, description="Inpaint Respective Field", ge=0.0, le=1.0)
invert_mask_checkbox: bool = Field(False, description="Invert Mask")
inpaint_erode_or_dilate: int = Field(0, description="Mask Erode or Dilate", ge=-64, le=64)


class Text2ImgRequest(BaseModel):
Expand Down
7 changes: 6 additions & 1 deletion fooocusapi/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ def __init__(self, prompt: str,
inpaint_engine = default_inpaint_engine_version
inpaint_strength = 1.0
inpaint_respective_field = 0.618
inpaint_mask_upload_checkbox = False
invert_mask_checkbox = False
inpaint_erode_or_dilate = 0


# Auto set mixing_image_prompt_and_inpaint to True
if len(self.image_prompts) > 0 and inpaint_input_image is not None:
Expand All @@ -171,7 +175,8 @@ def __init__(self, prompt: str,
debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, \
refiner_swap_method, \
freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \
debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field
debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \
inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate
]
else:
self.advanced_params = advanced_params
4 changes: 2 additions & 2 deletions fooocusapi/repositories_versions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os

fooocus_version = '2.1.854'
fooocus_version = '2.1.860'
fooocus_commit_hash = os.environ.get(
'FOOOCUS_COMMIT_HASH', "eb0b4d51ef3f46f57d7f20e870aa89a4b5de48ef")
'FOOOCUS_COMMIT_HASH', "624f74a1ed78ea09467c856cef35aeee0af863f6")
39 changes: 29 additions & 10 deletions fooocusapi/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def process_generate(async_task: QueueTask, params: ImageGenerationParams) -> Li
import extras.ip_adapter as ip_adapter
import extras.face_crop as face_crop
import ldm_patched.modules.model_management as model_management
from modules.util import remove_empty_str, resize_image, HWC3, set_image_shape_ceil, get_image_shape_ceil, get_shape_ceil, resample_image
from modules.util import remove_empty_str, resize_image, HWC3, set_image_shape_ceil, get_image_shape_ceil, get_shape_ceil, resample_image, erode_or_dilate
from modules.private_logger import log
from modules.upscaler import perform_upscale
from extras.expansion import safe_str
Expand Down Expand Up @@ -134,18 +134,11 @@ def yield_result(_, imgs, tasks):
outpaint_distance_bottom = params.outpaint_distance_bottom
inpaint_input_image = params.inpaint_input_image
inpaint_additional_prompt = params.inpaint_additional_prompt
inpaint_mask_image_upload = None

if inpaint_additional_prompt is None:
inpaint_additional_prompt = ''

if inpaint_input_image is not None and inpaint_input_image['image'] is not None:
inpaint_image_size = inpaint_input_image['image'].shape[:2]
if inpaint_input_image['mask'] is None:
inpaint_input_image['mask'] = np.zeros(inpaint_image_size, dtype=np.uint8)
inpaint_input_image['mask'] = HWC3(inpaint_input_image['mask'])
if inpaint_input_image['mask'].shape[:2] != inpaint_image_size:
# Reset inpaint mask
inpaint_input_image['mask'] = resize_image(inpaint_input_image['mask'], width=inpaint_image_size[1], height=inpaint_image_size[0], resize_mode=0)

image_seed = refresh_seed(image_seed is None, image_seed)

cn_tasks = {x: [] for x in flags.ip_list}
Expand All @@ -155,6 +148,16 @@ def yield_result(_, imgs, tasks):

advanced_parameters.set_all_advanced_parameters(*params.advanced_params)

if inpaint_input_image is not None and inpaint_input_image['image'] is not None:
inpaint_image_size = inpaint_input_image['image'].shape[:2]
if inpaint_input_image['mask'] is None:
inpaint_input_image['mask'] = np.zeros(inpaint_image_size, dtype=np.uint8)
else:
advanced_parameters.inpaint_mask_upload_checkbox = True

inpaint_input_image['mask'] = HWC3(inpaint_input_image['mask'])
inpaint_mask_image_upload = inpaint_input_image['mask']

# Fooocus async_worker.py code start

outpaint_selections = [o.lower() for o in outpaint_selections]
Expand Down Expand Up @@ -289,6 +292,22 @@ def yield_result(_, imgs, tasks):
and isinstance(inpaint_input_image, dict):
inpaint_image = inpaint_input_image['image']
inpaint_mask = inpaint_input_image['mask'][:, :, 0]

if advanced_parameters.inpaint_mask_upload_checkbox:
if isinstance(inpaint_mask_image_upload, np.ndarray):
if inpaint_mask_image_upload.ndim == 3:
H, W, C = inpaint_image.shape
inpaint_mask_image_upload = resample_image(inpaint_mask_image_upload, width=W, height=H)
inpaint_mask_image_upload = np.mean(inpaint_mask_image_upload, axis=2)
inpaint_mask_image_upload = (inpaint_mask_image_upload > 127).astype(np.uint8) * 255
inpaint_mask = inpaint_mask_image_upload

if int(advanced_parameters.inpaint_erode_or_dilate) != 0:
inpaint_mask = erode_or_dilate(inpaint_mask, advanced_parameters.inpaint_erode_or_dilate)

if advanced_parameters.invert_mask_checkbox:
inpaint_mask = 255 - inpaint_mask

inpaint_image = HWC3(inpaint_image)
if isinstance(inpaint_image, np.ndarray) and isinstance(inpaint_mask, np.ndarray) \
and (np.any(inpaint_mask > 127) or len(outpaint_selections) > 0):
Expand Down

0 comments on commit 3601658

Please sign in to comment.