From ee523644d9c84d5e466b57cff63f34306fe762f9 Mon Sep 17 00:00:00 2001 From: Konie Date: Mon, 16 Oct 2023 15:17:48 +0800 Subject: [PATCH] Merge Fooocus v2.1.679 --- README.md | 2 +- fooocusapi/models.py | 3 ++ fooocusapi/parameters.py | 3 ++ fooocusapi/repositories_versions.py | 6 +-- fooocusapi/worker.py | 17 +++---- main.py | 73 ++++++++++------------------- 6 files changed, 42 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index cfb033a..429a8ca 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ FastAPI powered API for [Fooocus](https://github.com/lllyasviel/Fooocus) -Currently loaded Fooocus version: 2.1.44 +Currently loaded Fooocus version: 2.1.679 ### Run with Replicate Now you can use Fooocus-API by Replicate, the model is in [konieshadow/fooocus-api](https://replicate.com/konieshadow/fooocus-api). diff --git a/fooocusapi/models.py b/fooocusapi/models.py index 4646de8..a5d8096 100644 --- a/fooocusapi/models.py +++ b/fooocusapi/models.py @@ -27,6 +27,9 @@ class PerfomanceSelection(str, Enum): class FooocusStyle(str, Enum): fooocus_expansion = 'Fooocus V2' default = 'Default (Slightly Cinematic)' + fooocus_anime = 'Fooocus Anime' + fooocus_realistic = 'Fooocus Realistic' + fooocus_strong_negative = 'Fooocus Strong Negative' sai_3d_model = 'SAI 3D Model' sai_analog_film = 'SAI Analog Film' sai_anime = 'SAI Anime' diff --git a/fooocusapi/parameters.py b/fooocusapi/parameters.py index a81c699..57aed13 100644 --- a/fooocusapi/parameters.py +++ b/fooocusapi/parameters.py @@ -9,6 +9,9 @@ fooocus_styles = [ 'Fooocus V2', 'Default (Slightly Cinematic)', + 'Fooocus Anime', + 'Fooocus Realistic', + 'Fooocus Strong Negative', 'SAI 3D Model', 'SAI Analog Film', 'SAI Anime', diff --git a/fooocusapi/repositories_versions.py b/fooocusapi/repositories_versions.py index b1d0f00..1916bb8 100644 --- a/fooocusapi/repositories_versions.py +++ b/fooocusapi/repositories_versions.py @@ -1,7 +1,5 @@ import os -fooocus_version = '2.1.44' -comfy_commit_hash = os.environ.get( - 'COMFY_COMMIT_HASH', "d1a0abd40b86f3f079b0cc71e49f9f4604831457") +fooocus_version = '2.1.679' fooocus_commit_hash = os.environ.get( - 'FOOOCUS_COMMIT_HASH', "5e8f2f96e91817cc6691642e71edec8b8264b114") + 'FOOOCUS_COMMIT_HASH', "589409e3f4832014b931884eac6963997de01739") diff --git a/fooocusapi/worker.py b/fooocusapi/worker.py index 510ae3f..e3abcea 100644 --- a/fooocusapi/worker.py +++ b/fooocusapi/worker.py @@ -20,7 +20,7 @@ def process_generate(params: ImageGenerationParams) -> List[ImageGenerationResul import modules.core as core import modules.inpaint_worker as inpaint_worker import modules.path as path - import comfy.model_management as model_management + import fcbh.model_management as model_management import modules.advanced_parameters as advanced_parameters import fooocus_extras.preprocessors as preprocessors import fooocus_extras.ip_adapter as ip_adapter @@ -119,6 +119,7 @@ def build_advanced_parameters(): canny_low_threshold = 64 canny_high_threshold = 128 inpaint_engine = inpaint_model_version + refiner_swap_method = 'joint' freeu_enabled = False freeu_b1, freeu_b2, freeu_s1, freeu_s2 = [None] * 4 return [adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name, @@ -126,7 +127,7 @@ def build_advanced_parameters(): overwrite_vary_strength, overwrite_upscale_strength, mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint, debugging_cn_preprocessor, controlnet_softness, canny_low_threshold, canny_high_threshold, inpaint_engine, - freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2] + refiner_swap_method, freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2] advanced_parameters.set_all_advanced_parameters(*build_advanced_parameters()) @@ -165,6 +166,7 @@ def build_advanced_parameters(): inpaint_worker.current_task = None width, height = aspect_ratios[aspect_ratios_selection] skip_prompt_processing = False + refiner_swap_method = advanced_parameters.refiner_swap_method raw_prompt = prompt raw_negative_prompt = negative_prompt @@ -228,7 +230,7 @@ def build_advanced_parameters(): loras += [(inpaint_patch_model_path, 1.0)] print(f'[Inpaint] Current inpaint model is {inpaint_patch_model_path}') goals.append('inpaint') - sampler_name = 'dpmpp_fooocus_2m_sde_inpaint_seamless' + sampler_name = 'dpmpp_2m_sde_gpu' # only support the patched dpmpp_2m_sde_gpu if current_tab == 'ip' or \ advanced_parameters.mixing_image_prompt_and_inpaint or \ advanced_parameters.mixing_image_prompt_and_vary_upscale: @@ -530,12 +532,6 @@ def build_advanced_parameters(): print(f'Preparation time: {preparation_time:.2f} seconds') outputs.append(['preview', (13, 'Moving model to GPU ...', None)]) - execution_start_time = time.perf_counter() - model_management.load_models_gpu([pipeline.final_unet]) - moving_time = time.perf_counter() - execution_start_time - print(f'Moving model to GPU: {moving_time:.2f} seconds') - - outputs.append(['preview', (13, 'Starting tasks ...', None)]) def callback(step, x0, x, total_steps, y): done_steps = current_task_id * steps + step @@ -574,7 +570,8 @@ def callback(step, x0, x, total_steps, y): latent=initial_latent, denoise=denoising_strength, tiled=tiled, - cfg_scale=cfg_scale + cfg_scale=cfg_scale, + refiner_swap_method=advanced_parameters.refiner_swap_method ) del task['c'], task['uc'], positive_cond, negative_cond # Save memory diff --git a/main.py b/main.py index c1fc038..d422316 100644 --- a/main.py +++ b/main.py @@ -6,9 +6,7 @@ from importlib.util import find_spec from fooocus_api_version import version -from fooocusapi.repositories_versions import (comfy_commit_hash, - fooocus_commit_hash, - fooocus_version) +from fooocusapi.repositories_versions import fooocus_commit_hash os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1" @@ -16,7 +14,6 @@ default_command_live = True index_url = os.environ.get('INDEX_URL', "") -comfyui_name = 'ComfyUI-from-StabilityAI-Official' fooocus_name = 'Fooocus' modules_path = os.path.dirname(os.path.realpath(__file__)) @@ -134,12 +131,6 @@ def download_repositories(): print(f"Using https proxy for git clone: {https_proxy}") os.environ['https_proxy'] = https_proxy - # Check and download ComfyUI - comfy_repo = os.environ.get( - 'COMFY_REPO', "https://github.com/comfyanonymous/ComfyUI") - git_clone(comfy_repo, repo_dir(comfyui_name), - "Inference Engine", comfy_commit_hash) - # Check and download Fooocus fooocus_repo = os.environ.get( 'FOOOCUS_REPO', 'https://github.com/lllyasviel/Fooocus') @@ -157,37 +148,25 @@ def is_installed(package): def download_models(): - model_filenames = [ - ('sd_xl_base_1.0_0.9vae.safetensors', - 'https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0_0.9vae.safetensors'), - ('sd_xl_refiner_1.0_0.9vae.safetensors', - 'https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0/resolve/main/sd_xl_refiner_1.0_0.9vae.safetensors') - ] - - lora_filenames = [ - ('sd_xl_offset_example-lora_1.0.safetensors', - 'https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_offset_example-lora_1.0.safetensors') - ] - vae_approx_filenames = [ - ('xlvaeapp.pth', - 'https://huggingface.co/lllyasviel/misc/resolve/main/xlvaeapp.pth') + ('xlvaeapp.pth', 'https://huggingface.co/lllyasviel/misc/resolve/main/xlvaeapp.pth'), + ('vaeapp_sd15.pth', 'https://huggingface.co/lllyasviel/misc/resolve/main/vaeapp_sd15.pt'), + ('xl-to-v1_interposer-v3.1.safetensors', + 'https://huggingface.co/lllyasviel/misc/resolve/main/xl-to-v1_interposer-v3.1.safetensors') ] from modules.model_loader import load_file_from_url - from modules.path import (fooocus_expansion_path, lorafile_path, - modelfile_path, upscale_models_path, - vae_approx_path) - - for file_name, url in model_filenames: - load_file_from_url(url=url, model_dir=modelfile_path, - file_name=file_name) - for file_name, url in lora_filenames: - load_file_from_url(url=url, model_dir=lorafile_path, - file_name=file_name) + from modules.path import modelfile_path, lorafile_path, vae_approx_path, fooocus_expansion_path, \ + checkpoint_downloads, embeddings_path, embeddings_downloads, lora_downloads + + for file_name, url in checkpoint_downloads.items(): + load_file_from_url(url=url, model_dir=modelfile_path, file_name=file_name) + for file_name, url in embeddings_downloads.items(): + load_file_from_url(url=url, model_dir=embeddings_path, file_name=file_name) + for file_name, url in lora_downloads.items(): + load_file_from_url(url=url, model_dir=lorafile_path, file_name=file_name) for file_name, url in vae_approx_filenames: - load_file_from_url( - url=url, model_dir=vae_approx_path, file_name=file_name) + load_file_from_url(url=url, model_dir=vae_approx_path, file_name=file_name) load_file_from_url( url='https://huggingface.co/lllyasviel/misc/resolve/main/fooocus_expansion.bin', @@ -228,14 +207,18 @@ def prepare_environments(args) -> bool: if not skip_sync_repo: download_repositories() - # Add indent repositories to import path - sys.path.append(os.path.join(script_path, dir_repos, comfyui_name)) - sys.path.append(os.path.join(script_path, dir_repos, fooocus_name)) - - download_models() + # Add dependent repositories to import path + sys.path.append(script_path) + fooocus_path = os.path.join(script_path, dir_repos, fooocus_name) + sys.path.append(fooocus_path) + backend_path = os.path.join(fooocus_path, 'backend', 'headless') + if backend_path not in sys.path: + sys.path.append(backend_path) + os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1" sys.argv = [sys.argv[0]] - ini_comfy_args() + download_models() + ini_cbh_args() if args.preload_pipeline: print("Preload pipeline") @@ -256,9 +239,6 @@ class Args(object): args.sync_repo = 'skip' prepare_environments(args) - sys.argv = [sys.argv[0]] - ini_comfy_args() - if disable_private_log: import fooocusapi.worker as worker worker.save_log = False @@ -275,7 +255,7 @@ class Args(object): # This function was copied from [Fooocus](https://github.com/lllyasviel/Fooocus) repository. -def ini_comfy_args(): +def ini_cbh_args(): from args_manager import args return args @@ -298,7 +278,6 @@ def ini_comfy_args(): args = parser.parse_args() if prepare_environments(args): - argv = sys.argv sys.argv = [sys.argv[0]] # Start api server