diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml
index 5b9cded68..d46966e5b 100644
--- a/.github/ISSUE_TEMPLATE/bug_report.yml
+++ b/.github/ISSUE_TEMPLATE/bug_report.yml
@@ -16,9 +16,9 @@ body:
description: |
Please perform basic debugging to see if your configuration is the cause of the issue.
Basic debug procedure
- 2. Update Fooocus - sometimes things just need to be updated
- 3. Backup and remove your config.txt - check if the issue is caused by bad configuration
- 5. Try a fresh installation of Fooocus in a different directory - see if a clean installation solves the issue
+ 1. Update Fooocus - sometimes things just need to be updated
+ 2. Backup and remove your config.txt - check if the issue is caused by bad configuration
+ 3. Try a fresh installation of Fooocus in a different directory - see if a clean installation solves the issue
Before making a issue report please, check that the issue hasn't been reported recently.
options:
- label: The issue has not been resolved by following the [troubleshooting guide](https://github.com/lllyasviel/Fooocus/blob/main/troubleshoot.md)
diff --git a/apis/models/requests.py b/apis/models/requests.py
index d67b9afe2..9514e7d73 100644
--- a/apis/models/requests.py
+++ b/apis/models/requests.py
@@ -126,6 +126,7 @@ class CommonRequest(BaseModel):
inpaint_advanced_masking_checkbox: bool = Field(default=False, description="Inpaint Advanced Masking Checkbox")
invert_mask_checkbox: bool = Field(default=False, description="Inpaint Invert Mask Checkbox")
inpaint_erode_or_dilate: int = Field(default=0, ge=-64, le=64, description="Inpaint Erode or Dilate")
+ save_final_enhanced_image_only: bool = Field(default=False, description="Save final enhanced image only")
save_metadata_to_images: bool = Field(default=True, description="Save meta data")
metadata_scheme: MetadataScheme = Field(default=MetadataScheme.FOOOCUS, description="Meta data scheme, one of [fooocus, a111]")
controlnet_image: List[ImagePrompt] = Field(default=[ImagePrompt()], description="ControlNet Image Prompt")
diff --git a/apis/routes/query.py b/apis/routes/query.py
index f16a6f7a7..9e9b271fd 100644
--- a/apis/routes/query.py
+++ b/apis/routes/query.py
@@ -1,6 +1,7 @@
"""
Query routes.
"""
+import os
import re
import json
@@ -154,6 +155,9 @@ async def get_output(dir_name: str, file_name: str, accept: str = Header(None)):
"""
Get a specific output by its ID.
"""
+ if not os.path.exists(f"{path_outputs}/{dir_name}/{file_name}"):
+ return Response(status_code=404)
+
accept_formats = ('png', 'jpg', 'jpeg', 'webp')
try:
_, ext = accept.lower().split("/")
@@ -179,6 +183,9 @@ async def get_input(file_name: str, accept: str = Header(None)):
"""
Get a specific input by its ID.
"""
+ if not os.path.exists(f"inputs/{file_name}"):
+ return Response(status_code=404)
+
accept_formats = ('png', 'jpg', 'jpeg', 'webp')
try:
_, ext = accept.lower().split("/")
diff --git a/apis/utils/api_utils.py b/apis/utils/api_utils.py
index 3d1f0e37f..90b0187cd 100644
--- a/apis/utils/api_utils.py
+++ b/apis/utils/api_utils.py
@@ -97,6 +97,7 @@ def params_to_params(req: object) -> list:
req.inpaint_advanced_masking_checkbox,
req.invert_mask_checkbox,
req.inpaint_erode_or_dilate,
+ req.save_final_enhanced_image_only,
req.save_metadata_to_images,
req.metadata_scheme.value,
diff --git a/apis/utils/post_worker.py b/apis/utils/post_worker.py
index 3af4aa59c..840599c14 100644
--- a/apis/utils/post_worker.py
+++ b/apis/utils/post_worker.py
@@ -13,7 +13,7 @@
from apis.utils.sql_client import GenerateRecord
from apis.utils.web_hook import send_result_to_web_hook
from modules.async_worker import AsyncTask
-from modules.config import path_outputs
+from modules.config import path_outputs, temp_path
ROOT_DIR = file_utils.SCRIPT_PATH
@@ -37,7 +37,14 @@ async def post_worker(task: AsyncTask, started_at: int, target_name: str, ext: s
:param ext:
:return: The task.
"""
+ final_enhanced = []
task_status = "finished"
+ if task.save_final_enhanced_image_only:
+ for item in task.results:
+ if temp_path not in item:
+ final_enhanced.append(item)
+ task.results = final_enhanced
+
if task.last_stop in ['stop', 'skip']:
task_status = task.last_stop
try:
diff --git a/apis/utils/pre_process.py b/apis/utils/pre_process.py
index 26f192f3b..48165ab75 100644
--- a/apis/utils/pre_process.py
+++ b/apis/utils/pre_process.py
@@ -7,8 +7,12 @@
import numpy as np
-from modules.config import default_max_lora_number, try_get_preset_content
-from modules.flags import Performance, controlnet_image_count
+from modules.config import (
+ default_max_lora_number,
+ try_get_preset_content,
+ default_controlnet_image_count
+)
+from modules.flags import Performance
from modules import constants, config
from modules.model_loader import load_file_from_url
@@ -78,10 +82,10 @@ async def control_net_parser(control_net: list) -> list:
"cn_weight": 0.6,
"cn_type": "ImagePrompt"
}
- while len(control_net) < controlnet_image_count:
+ while len(control_net) < default_controlnet_image_count:
control_net.append(ImagePrompt(**default_cn_image))
- control_net = control_net[:controlnet_image_count]
+ control_net = control_net[:default_controlnet_image_count]
cn_list = []
for cn in control_net:
cn_list.extend([
diff --git a/args_manager.py b/args_manager.py
index ccda9dcdd..7c106d26a 100644
--- a/args_manager.py
+++ b/args_manager.py
@@ -17,7 +17,7 @@
args_parser.parser.add_argument("--theme", type=str, help="launches the UI with light or dark theme", default=None)
args_parser.parser.add_argument("--disable-image-log", action='store_true',
- help="Prevent writing images and logs to hard drive.")
+ help="Prevent writing images and logs to the outputs folder.")
args_parser.parser.add_argument("--disable-analytics", action='store_true',
help="Disables analytics for Gradio.")
@@ -28,6 +28,9 @@
args_parser.parser.add_argument("--disable-preset-download", action='store_true',
help="Disables downloading models for presets", default=False)
+args_parser.parser.add_argument("--disable-enhance-output-sorting", action='store_true',
+ help="Disables enhance output sorting for final image gallery.")
+
args_parser.parser.add_argument("--enable-auto-describe-image", action='store_true',
help="Enables automatic description of uov and enhance image when prompt is empty", default=False)
diff --git a/fooocus_version.py b/fooocus_version.py
index 3d98bc1d1..ca4825b5b 100644
--- a/fooocus_version.py
+++ b/fooocus_version.py
@@ -1 +1 @@
-version = '2.5.0'
+version = '2.5.2'
diff --git a/language/en.json b/language/en.json
index c14b38758..a0935643a 100644
--- a/language/en.json
+++ b/language/en.json
@@ -68,6 +68,9 @@
"Read wildcards in order": "Read wildcards in order",
"Black Out NSFW": "Black Out NSFW",
"Use black image if NSFW is detected.": "Use black image if NSFW is detected.",
+ "Save only final enhanced image": "Save only final enhanced image",
+ "Save Metadata to Images": "Save Metadata to Images",
+ "Adds parameters to generated images allowing manual regeneration.": "Adds parameters to generated images allowing manual regeneration.",
"\ud83d\udcda History Log": "\uD83D\uDCDA History Log",
"Image Style": "Image Style",
"Fooocus V2": "Fooocus V2",
diff --git a/modules/async_worker.py b/modules/async_worker.py
index a133b1cea..6a3aae4db 100644
--- a/modules/async_worker.py
+++ b/modules/async_worker.py
@@ -11,7 +11,7 @@
class AsyncTask:
def __init__(self, args, task_id=uuid.uuid4().hex):
- from modules.flags import Performance, MetadataScheme, ip_list, controlnet_image_count
+ from modules.flags import Performance, MetadataScheme, ip_list, disabled
from modules.util import get_enabled_loras
from modules.config import default_max_lora_number
import args_manager
@@ -98,12 +98,13 @@ def __init__(self, args, task_id=uuid.uuid4().hex):
self.inpaint_advanced_masking_checkbox = args.pop()
self.invert_mask_checkbox = args.pop()
self.inpaint_erode_or_dilate = args.pop()
+ self.save_final_enhanced_image_only = args.pop() if not args_manager.args.disable_image_log else False
self.save_metadata_to_images = args.pop() if not args_manager.args.disable_metadata else False
self.metadata_scheme = MetadataScheme(
args.pop()) if not args_manager.args.disable_metadata else MetadataScheme.FOOOCUS
self.cn_tasks = {x: [] for x in ip_list}
- for _ in range(controlnet_image_count):
+ for _ in range(modules.config.default_controlnet_image_count):
cn_img = args.pop()
cn_stop = args.pop()
cn_weight = args.pop()
@@ -156,6 +157,10 @@ def __init__(self, args, task_id=uuid.uuid4().hex):
enhance_inpaint_erode_or_dilate,
enhance_mask_invert
])
+ self.should_enhance = self.enhance_checkbox and (self.enhance_uov_method != disabled.casefold() or len(self.enhance_ctrls) > 0)
+ self.images_to_enhance_count = 0
+ self.enhance_stats = {}
+
try:
self.outpaint_distance = args.pop()
except IndexError:
@@ -165,7 +170,7 @@ def __init__(self, args, task_id=uuid.uuid4().hex):
async_tasks = []
-class EarlyReturnException:
+class EarlyReturnException(BaseException):
pass
@@ -173,6 +178,7 @@ def worker():
global async_tasks
import os
+ import traceback
import math
import numpy as np
import torch
@@ -283,7 +289,7 @@ def build_image_wall(async_task):
def process_task(all_steps, async_task, callback, controlnet_canny_path, controlnet_cpds_path, current_task_id,
denoising_strength, final_scheduler_name, goals, initial_latent, steps, switch, positive_cond,
negative_cond, task, loras, tiled, use_expansion, width, height, base_progress, preparation_steps,
- total_count, show_intermediate_results):
+ total_count, show_intermediate_results, persist_image=True):
if async_task.last_stop is not False:
ldm_patched.modules.model_management.interrupt_current_processing()
if 'cn' in goals:
@@ -320,9 +326,8 @@ def process_task(all_steps, async_task, callback, controlnet_canny_path, control
if modules.config.default_black_out_nsfw or async_task.black_out_nsfw:
progressbar(async_task, current_progress, 'Checking for NSFW content ...')
imgs = default_censor(imgs)
- progressbar(async_task, current_progress,
- f'Saving image {current_task_id + 1}/{total_count} to system ...')
- img_paths = save_and_log(async_task, height, imgs, task, use_expansion, width, loras)
+ progressbar(async_task, current_progress, f'Saving image {current_task_id + 1}/{total_count} to system ...')
+ img_paths = save_and_log(async_task, height, imgs, task, use_expansion, width, loras, persist_image)
yield_result(async_task, img_paths, current_progress, async_task.black_out_nsfw, False,
do_not_show_finished_images=not show_intermediate_results or async_task.disable_intermediate_results)
@@ -338,7 +343,7 @@ def apply_patch_settings(async_task):
async_task.adaptive_cfg
)
- def save_and_log(async_task, height, imgs, task, use_expansion, width, loras) -> list:
+ def save_and_log(async_task, height, imgs, task, use_expansion, width, loras, persist_image=True) -> list:
img_paths = []
for x in imgs:
d = [('Prompt', 'prompt', task['log_positive_prompt']),
@@ -393,7 +398,7 @@ def save_and_log(async_task, height, imgs, task, use_expansion, width, loras) ->
d.append(('Metadata Scheme', 'metadata_scheme',
async_task.metadata_scheme.value if async_task.save_metadata_to_images else async_task.save_metadata_to_images))
d.append(('Version', 'version', 'Fooocus v' + fooocus_version.version))
- img_paths.append(log(x, d, metadata_parser, async_task.output_format, task))
+ img_paths.append(log(x, d, metadata_parser, async_task.output_format, task, persist_image))
return img_paths
@@ -723,13 +728,20 @@ def process_prompt(async_task, prompt, negative_prompt, base_model_additional_lo
task_styles = async_task.style_selections.copy()
if use_style:
+ placeholder_replaced = False
+
for j, s in enumerate(task_styles):
if s == random_style_name:
s = get_random_style(task_rng)
task_styles[j] = s
- p, n = apply_style(s, positive=task_prompt)
+ p, n, style_has_placeholder = apply_style(s, positive=task_prompt)
+ if style_has_placeholder:
+ placeholder_replaced = True
positive_basic_workloads = positive_basic_workloads + p
negative_basic_workloads = negative_basic_workloads + n
+
+ if not placeholder_replaced:
+ positive_basic_workloads = [task_prompt] + positive_basic_workloads
else:
positive_basic_workloads.append(task_prompt)
@@ -994,7 +1006,7 @@ def process_enhance(all_steps, async_task, callback, controlnet_canny_path, cont
inpaint_engine, inpaint_respective_field, inpaint_strength,
prompt, negative_prompt, final_scheduler_name, goals, height, img, mask,
preparation_steps, steps, switch, tiled, total_count, use_expansion, use_style,
- use_synthetic_refiner, width, show_intermediate_results=True):
+ use_synthetic_refiner, width, show_intermediate_results=True, persist_image=True):
base_model_additional_loras = []
inpaint_head_model_path = None
inpaint_parameterized = inpaint_engine != 'None' # inpaint_engine = None, improve detail
@@ -1015,7 +1027,7 @@ def process_enhance(all_steps, async_task, callback, controlnet_canny_path, cont
progressbar(async_task, current_progress, 'Checking for NSFW content ...')
img = default_censor(img)
progressbar(async_task, current_progress, f'Saving image {current_task_id + 1}/{total_count} to system ...')
- uov_image_path = log(img, d, output_format=async_task.output_format)
+ uov_image_path = log(img, d, output_format=async_task.output_format, persist_image=persist_image)
yield_result(async_task, uov_image_path, current_progress, async_task.black_out_nsfw, False,
do_not_show_finished_images=not show_intermediate_results or async_task.disable_intermediate_results)
return current_progress, img, prompt, negative_prompt
@@ -1049,7 +1061,8 @@ def process_enhance(all_steps, async_task, callback, controlnet_canny_path, cont
final_scheduler_name, goals, initial_latent, steps, switch,
task_enhance['c'], task_enhance['uc'], task_enhance, loras,
tiled, use_expansion, width, height, current_progress,
- preparation_steps, total_count, show_intermediate_results)
+ preparation_steps, total_count, show_intermediate_results,
+ persist_image)
del task_enhance['c'], task_enhance['uc'] # Save memory
return current_progress, imgs[0], prompt, negative_prompt
@@ -1057,7 +1070,7 @@ def process_enhance(all_steps, async_task, callback, controlnet_canny_path, cont
def enhance_upscale(all_steps, async_task, base_progress, callback, controlnet_canny_path, controlnet_cpds_path,
current_task_id, denoising_strength, done_steps_inpainting, done_steps_upscaling, enhance_steps,
prompt, negative_prompt, final_scheduler_name, height, img, preparation_steps, switch, tiled,
- total_count, use_expansion, use_style, use_synthetic_refiner, width):
+ total_count, use_expansion, use_style, use_synthetic_refiner, width, persist_image=True):
# reset inpaint worker to prevent tensor size issues and not mix upscale and inpainting
inpaint_worker.current_task = None
@@ -1075,7 +1088,7 @@ def enhance_upscale(all_steps, async_task, base_progress, callback, controlnet_c
controlnet_cpds_path, current_progress, current_task_id, denoising_strength, False,
'None', 0.0, 0.0, prompt, negative_prompt, final_scheduler_name,
goals_enhance, height, img, None, preparation_steps, steps, switch, tiled, total_count,
- use_expansion, use_style, use_synthetic_refiner, width)
+ use_expansion, use_style, use_synthetic_refiner, width, persist_image=persist_image)
except ldm_patched.modules.model_management.InterruptProcessingException:
if async_task.last_stop == 'skip':
@@ -1192,6 +1205,8 @@ def handler(async_task: AsyncTask):
current_progress += 1
progressbar(async_task, current_progress, 'Image processing ...')
+ should_enhance = async_task.enhance_checkbox and (async_task.enhance_uov_method != flags.disabled.casefold() or len(async_task.enhance_ctrls) > 0)
+
if 'vary' in goals:
async_task.uov_input_image, denoising_strength, initial_latent, width, height, current_progress = apply_vary(
async_task, async_task.uov_method, denoising_strength, async_task.uov_input_image, switch,
@@ -1297,8 +1312,8 @@ def callback(step, x0, x, total_steps, y):
int(current_progress + async_task.callback_steps),
f'Sampling step {step + 1}/{total_steps}, image {current_task_id + 1}/{total_count} ...', y)])
- should_enhance = async_task.enhance_checkbox and (async_task.enhance_uov_method != flags.disabled.casefold() or len(async_task.enhance_ctrls) > 0)
- show_intermediate_results = len(tasks) > 1 or should_enhance
+ show_intermediate_results = len(tasks) > 1 or async_task.should_enhance
+ persist_image = not async_task.should_enhance or not async_task.save_final_enhanced_image_only
for current_task_id, task in enumerate(tasks):
progressbar(async_task, current_progress, f'Preparing task {current_task_id + 1}/{async_task.image_number} ...')
@@ -1311,7 +1326,8 @@ def callback(step, x0, x, total_steps, y):
initial_latent, async_task.steps, switch, task['c'],
task['uc'], task, loras, tiled, use_expansion, width,
height, current_progress, preparation_steps,
- async_task.image_number, show_intermediate_results)
+ async_task.image_number, show_intermediate_results,
+ persist_image)
current_progress = int(preparation_steps + (100 - preparation_steps) / float(all_steps) * async_task.steps * (current_task_id + 1))
images_to_enhance += imgs
@@ -1329,7 +1345,7 @@ def callback(step, x0, x, total_steps, y):
execution_time = time.perf_counter() - execution_start_time
print(f'Generating and saving time: {execution_time:.2f} seconds')
- if not should_enhance:
+ if not async_task.should_enhance:
print(f'[Enhance] Skipping, preconditions aren\'t met')
stop_processing(async_task, processing_start_time)
return
@@ -1338,9 +1354,14 @@ def callback(step, x0, x, total_steps, y):
active_enhance_tabs = len(async_task.enhance_ctrls)
should_process_enhance_uov = async_task.enhance_uov_method != flags.disabled.casefold()
+ enhance_uov_before = False
+ enhance_uov_after = False
if should_process_enhance_uov:
active_enhance_tabs += 1
+ enhance_uov_before = async_task.enhance_uov_processing_order == flags.enhancement_uov_before
+ enhance_uov_after = async_task.enhance_uov_processing_order == flags.enhancement_uov_after
total_count = len(images_to_enhance) * active_enhance_tabs
+ async_task.images_to_enhance_count = len(images_to_enhance)
base_progress = current_progress
current_task_id = -1
@@ -1348,19 +1369,23 @@ def callback(step, x0, x, total_steps, y):
done_steps_inpainting = 0
enhance_steps, _, _, _ = apply_overrides(async_task, async_task.original_steps, height, width)
exception_result = None
- for img in images_to_enhance:
+ for index, img in enumerate(images_to_enhance):
+ async_task.enhance_stats[index] = 0
enhancement_image_start_time = time.perf_counter()
last_enhance_prompt = async_task.prompt
last_enhance_negative_prompt = async_task.negative_prompt
- if should_process_enhance_uov and async_task.enhance_uov_processing_order == flags.enhancement_uov_before:
+ if enhance_uov_before:
current_task_id += 1
+ persist_image = not async_task.save_final_enhanced_image_only or active_enhance_tabs == 0
current_task_id, done_steps_inpainting, done_steps_upscaling, img, exception_result = enhance_upscale(
all_steps, async_task, base_progress, callback, controlnet_canny_path, controlnet_cpds_path,
current_task_id, denoising_strength, done_steps_inpainting, done_steps_upscaling, enhance_steps,
async_task.prompt, async_task.negative_prompt, final_scheduler_name, height, img, preparation_steps,
- switch, tiled, total_count, use_expansion, use_style, use_synthetic_refiner, width)
+ switch, tiled, total_count, use_expansion, use_style, use_synthetic_refiner, width, persist_image)
+ async_task.enhance_stats[index] += 1
+
if exception_result == 'continue':
continue
elif exception_result == 'break':
@@ -1372,6 +1397,8 @@ def callback(step, x0, x, total_steps, y):
current_progress = int(base_progress + (100 - preparation_steps) / float(all_steps) * (done_steps_upscaling + done_steps_inpainting))
progressbar(async_task, current_progress, f'Preparing enhancement {current_task_id + 1}/{total_count} ...')
enhancement_task_start_time = time.perf_counter()
+ is_last_enhance_for_image = (current_task_id + 1) % active_enhance_tabs == 0 and not enhance_uov_after
+ persist_image = not async_task.save_final_enhanced_image_only or is_last_enhance_for_image
extras = {}
if enhance_mask_model == 'sam':
@@ -1402,13 +1429,13 @@ def callback(step, x0, x, total_steps, y):
async_task.yields.append(['preview', (current_progress, 'Loading ...', mask)])
yield_result(async_task, mask, current_progress, async_task.black_out_nsfw, False,
async_task.disable_intermediate_results)
+ async_task.enhance_stats[index] += 1
print(f'[Enhance] {dino_detection_count} boxes detected')
print(f'[Enhance] {sam_detection_count} segments detected in boxes')
print(f'[Enhance] {sam_detection_on_mask_count} segments applied to mask')
- if enhance_mask_model == 'sam' and (
- dino_detection_count == 0 or not async_task.debugging_dino and sam_detection_on_mask_count == 0):
+ if enhance_mask_model == 'sam' and (dino_detection_count == 0 or not async_task.debugging_dino and sam_detection_on_mask_count == 0):
print(f'[Enhance] No "{enhance_mask_dino_prompt_text}" detected, skipping')
continue
@@ -1421,7 +1448,8 @@ def callback(step, x0, x, total_steps, y):
enhance_inpaint_engine, enhance_inpaint_respective_field, enhance_inpaint_strength,
enhance_prompt, enhance_negative_prompt, final_scheduler_name, goals_enhance, height, img, mask,
preparation_steps, enhance_steps, switch, tiled, total_count, use_expansion, use_style,
- use_synthetic_refiner, width)
+ use_synthetic_refiner, width, persist_image=persist_image)
+ async_task.enhance_stats[index] += 1
if (should_process_enhance_uov and async_task.enhance_uov_processing_order == flags.enhancement_uov_after
and async_task.enhance_uov_prompt_type == flags.enhancement_uov_prompt_type_last_filled):
@@ -1448,14 +1476,18 @@ def callback(step, x0, x, total_steps, y):
if exception_result == 'break':
break
- if should_process_enhance_uov and async_task.enhance_uov_processing_order == flags.enhancement_uov_after:
+ if enhance_uov_after:
current_task_id += 1
+ # last step in enhance, always save
+ persist_image = True
current_task_id, done_steps_inpainting, done_steps_upscaling, img, exception_result = enhance_upscale(
all_steps, async_task, base_progress, callback, controlnet_canny_path, controlnet_cpds_path,
current_task_id, denoising_strength, done_steps_inpainting, done_steps_upscaling, enhance_steps,
last_enhance_prompt, last_enhance_negative_prompt, final_scheduler_name, height, img,
preparation_steps, switch, tiled, total_count, use_expansion, use_style, use_synthetic_refiner,
- width)
+ width, persist_image)
+ async_task.enhance_stats[index] += 1
+
if exception_result == 'continue':
continue
elif exception_result == 'break':
diff --git a/modules/config.py b/modules/config.py
index ee867e5fc..0f2038b61 100644
--- a/modules/config.py
+++ b/modules/config.py
@@ -403,12 +403,36 @@ def init_temp_path(path: str | None, default_path: str) -> str:
validator=lambda x: x in Performance.values(),
expected_type=str
)
+default_image_prompt_checkbox = get_config_item_or_set_default(
+ key='default_image_prompt_checkbox',
+ default_value=False,
+ validator=lambda x: isinstance(x, bool),
+ expected_type=bool
+)
+default_enhance_checkbox = get_config_item_or_set_default(
+ key='default_enhance_checkbox',
+ default_value=False,
+ validator=lambda x: isinstance(x, bool),
+ expected_type=bool
+)
default_advanced_checkbox = get_config_item_or_set_default(
key='default_advanced_checkbox',
default_value=False,
validator=lambda x: isinstance(x, bool),
expected_type=bool
)
+default_developer_debug_mode_checkbox = get_config_item_or_set_default(
+ key='default_developer_debug_mode_checkbox',
+ default_value=False,
+ validator=lambda x: isinstance(x, bool),
+ expected_type=bool
+)
+default_image_prompt_advanced_checkbox = get_config_item_or_set_default(
+ key='default_image_prompt_advanced_checkbox',
+ default_value=False,
+ validator=lambda x: isinstance(x, bool),
+ expected_type=bool
+)
default_max_image_number = get_config_item_or_set_default(
key='default_max_image_number',
default_value=32,
@@ -469,6 +493,65 @@ def init_temp_path(path: str | None, default_path: str) -> str:
validator=lambda x: x in modules.flags.inpaint_engine_versions,
expected_type=str
)
+default_selected_image_input_tab_id = get_config_item_or_set_default(
+ key='default_selected_image_input_tab_id',
+ default_value=modules.flags.default_input_image_tab,
+ validator=lambda x: x in modules.flags.input_image_tab_ids,
+ expected_type=str
+)
+default_uov_method = get_config_item_or_set_default(
+ key='default_uov_method',
+ default_value=modules.flags.disabled,
+ validator=lambda x: x in modules.flags.uov_list,
+ expected_type=str
+)
+default_controlnet_image_count = get_config_item_or_set_default(
+ key='default_controlnet_image_count',
+ default_value=4,
+ validator=lambda x: isinstance(x, int) and x > 0,
+ expected_type=int
+)
+default_ip_images = {}
+default_ip_stop_ats = {}
+default_ip_weights = {}
+default_ip_types = {}
+
+for image_count in range(default_controlnet_image_count):
+ image_count += 1
+ default_ip_images[image_count] = get_config_item_or_set_default(
+ key=f'default_ip_image_{image_count}',
+ default_value=None,
+ validator=lambda x: x is None or isinstance(x, str) and os.path.exists(x),
+ expected_type=str
+ )
+ default_ip_types[image_count] = get_config_item_or_set_default(
+ key=f'default_ip_type_{image_count}',
+ default_value=modules.flags.default_ip,
+ validator=lambda x: x in modules.flags.ip_list,
+ expected_type=str
+ )
+
+ default_end, default_weight = modules.flags.default_parameters[default_ip_types[image_count]]
+
+ default_ip_stop_ats[image_count] = get_config_item_or_set_default(
+ key=f'default_ip_stop_at_{image_count}',
+ default_value=default_end,
+ validator=lambda x: isinstance(x, float) and 0 <= x <= 1,
+ expected_type=float
+ )
+ default_ip_weights[image_count] = get_config_item_or_set_default(
+ key=f'default_ip_weight_{image_count}',
+ default_value=default_weight,
+ validator=lambda x: isinstance(x, float) and 0 <= x <= 2,
+ expected_type=float
+ )
+
+default_inpaint_advanced_masking_checkbox = get_config_item_or_set_default(
+ key='default_inpaint_advanced_masking_checkbox',
+ default_value=False,
+ validator=lambda x: isinstance(x, bool),
+ expected_type=bool
+)
default_inpaint_method = get_config_item_or_set_default(
key='default_inpaint_method',
default_value=modules.flags.inpaint_option_default,
@@ -526,12 +609,6 @@ def init_temp_path(path: str | None, default_path: str) -> str:
validator=lambda x: isinstance(x, int) and 1 <= x <= 5,
expected_type=int
)
-default_enhance_checkbox = get_config_item_or_set_default(
- key='default_enhance_checkbox',
- default_value=False,
- validator=lambda x: isinstance(x, bool),
- expected_type=bool
-)
default_enhance_uov_method = get_config_item_or_set_default(
key='default_enhance_uov_method',
default_value=modules.flags.disabled,
@@ -562,6 +639,12 @@ def init_temp_path(path: str | None, default_path: str) -> str:
validator=lambda x: isinstance(x, bool),
expected_type=bool
)
+default_save_only_final_enhanced_image = get_config_item_or_set_default(
+ key='default_save_only_final_enhanced_image',
+ default_value=False,
+ validator=lambda x: isinstance(x, bool),
+ expected_type=bool
+)
default_save_metadata_to_images = get_config_item_or_set_default(
key='default_save_metadata_to_images',
default_value=False,
@@ -584,6 +667,13 @@ def init_temp_path(path: str | None, default_path: str) -> str:
example_inpaint_prompts = [[x] for x in example_inpaint_prompts]
example_enhance_detection_prompts = [[x] for x in example_enhance_detection_prompts]
+default_invert_mask_checkbox = get_config_item_or_set_default(
+ key='default_invert_mask_checkbox',
+ default_value=False,
+ validator=lambda x: isinstance(x, bool),
+ expected_type=bool
+)
+
default_inpaint_mask_model = get_config_item_or_set_default(
key='default_inpaint_mask_model',
default_value='isnet-general-use',
diff --git a/modules/flags.py b/modules/flags.py
index 4b6cd7b59..4357cdf11 100644
--- a/modules/flags.py
+++ b/modules/flags.py
@@ -67,6 +67,9 @@
refiner_swap_method = 'joint'
+default_input_image_tab = 'uov_tab'
+input_image_tab_ids = ['uov_tab', 'ip_tab', 'inpaint_tab', 'describe_tab', 'enhance_tab', 'metadata_tab']
+
cn_ip = "ImagePrompt"
cn_ip_face = "FaceSwap"
cn_canny = "PyraCanny"
@@ -91,8 +94,8 @@
inpaint_option_modify = 'Modify Content (add objects, change background, etc.)'
inpaint_options = [inpaint_option_default, inpaint_option_detail, inpaint_option_modify]
-desc_type_photo = 'Photograph'
-desc_type_anime = 'Art/Anime'
+describe_type_photo = 'Photograph'
+describe_type_anime = 'Art/Anime'
sdxl_aspect_ratios = [
'704*1408', '704*1344', '768*1344', '768*1280', '832*1216', '832*1152',
@@ -113,8 +116,6 @@ class MetadataScheme(Enum):
(f'{MetadataScheme.A1111.value} (plain text)', MetadataScheme.A1111.value),
]
-controlnet_image_count = 4
-
class OutputFormat(Enum):
PNG = 'png'
diff --git a/modules/private_logger.py b/modules/private_logger.py
index 6fdb680c8..f758272e8 100644
--- a/modules/private_logger.py
+++ b/modules/private_logger.py
@@ -21,8 +21,8 @@ def get_current_html_path(output_format=None):
return html_name
-def log(img, metadata, metadata_parser: MetadataParser | None = None, output_format=None, task=None) -> str:
- path_outputs = modules.config.temp_path if args_manager.args.disable_image_log else modules.config.path_outputs
+def log(img, metadata, metadata_parser: MetadataParser | None = None, output_format=None, task=None, persist_image=True) -> str:
+ path_outputs = modules.config.temp_path if args_manager.args.disable_image_log or not persist_image else modules.config.path_outputs
output_format = output_format if output_format else modules.config.default_output_format
date_string, local_temp_filename, only_name = generate_temp_filename(folder=path_outputs, extension=output_format)
os.makedirs(os.path.dirname(local_temp_filename), exist_ok=True)
diff --git a/modules/sdxl_styles.py b/modules/sdxl_styles.py
index 12ab6c5ca..3feb886af 100644
--- a/modules/sdxl_styles.py
+++ b/modules/sdxl_styles.py
@@ -59,7 +59,7 @@ def get_random_style(rng: Random) -> str:
def apply_style(style, positive):
p, n = styles[style]
- return p.replace('{prompt}', positive).splitlines(), n.splitlines()
+ return p.replace('{prompt}', positive).splitlines(), n.splitlines(), '{prompt}' in p
def get_words(arrays, total_mult, index):
diff --git a/update_log.md b/update_log.md
index 9a0f3788f..e3a5e273d 100644
--- a/update_log.md
+++ b/update_log.md
@@ -1,3 +1,18 @@
+# [2.5.2](https://github.com/lllyasviel/Fooocus/releases/tag/v2.5.2)
+
+* Fix not adding positive prompt when styles didn't have a {prompt} placeholder in the positive prompt
+* Extend config settings for input image, see list in [PR](https://github.com/lllyasviel/Fooocus/pull/3382)
+
+# [2.5.1](https://github.com/lllyasviel/Fooocus/releases/tag/v2.5.1)
+
+* Update download URL in readme
+* Increase speed of metadata loading
+* Fix reading of metadata from jpeg, jpg and webp (exif)
+* Fix debug preprocessor
+* Update attributes and add inline prompt features section to readme
+* Add checkbox, config and handling for saving only the final enhanced image. Use config `default_save_only_final_enhanced_image`, default False.
+* Add sorting of final images when enhanced is enabled. Use argument `--disable-enhance-output-sorting` to disable.
+
# [2.5.0](https://github.com/lllyasviel/Fooocus/releases/tag/v2.5.0)
This version includes various package updates. If the auto-update doesn't work you can do one of the following:
diff --git a/webui.py b/webui.py
index d1b2e5690..05d9e222e 100644
--- a/webui.py
+++ b/webui.py
@@ -62,7 +62,7 @@ def generate_clicked(task: worker.AsyncTask):
# help bad internet connection by skipping duplicated preview
if len(task.yields) > 0: # if we have the next item
- if task.yields[0][0] == 'preview': # if the next item is also a preview
+ if task.yields[0][0] == 'preview': # if the next item is also a preview
# print('Skipped one preview for better internet connection.')
continue
@@ -77,6 +77,9 @@ def generate_clicked(task: worker.AsyncTask):
gr.update(visible=True, value=product), \
gr.update(visible=False)
if flag == 'finish':
+ if not args_manager.args.disable_enhance_output_sorting:
+ product = sort_enhance_images(product, task)
+
yield gr.update(visible=False), \
gr.update(visible=False), \
gr.update(visible=False), \
@@ -94,6 +97,25 @@ def generate_clicked(task: worker.AsyncTask):
return
+def sort_enhance_images(images, task):
+ if not task.should_enhance or len(images) <= task.images_to_enhance_count:
+ return images
+
+ sorted_images = []
+ walk_index = task.images_to_enhance_count
+
+ for index, enhanced_img in enumerate(images[:task.images_to_enhance_count]):
+ sorted_images.append(enhanced_img)
+ if index not in task.enhance_stats:
+ continue
+ target_index = walk_index + task.enhance_stats[index]
+ if walk_index < len(images) and target_index <= len(images):
+ sorted_images += images[walk_index:target_index]
+ walk_index += task.enhance_stats[index]
+
+ return sorted_images
+
+
def inpaint_mode_change(mode, inpaint_engine_version):
assert mode in modules.flags.inpaint_options
@@ -165,7 +187,6 @@ def inpaint_mode_change(mode, inpaint_engine_version):
skip_button = gr.Button(label="Skip", value="Skip", elem_classes='type_row_half', elem_id='skip_button', visible=False)
stop_button = gr.Button(label="Stop", value="Stop", elem_classes='type_row_half', elem_id='stop_button', visible=False)
-
def stop_clicked(currentTask):
import ldm_patched.modules.model_management as model_management
currentTask.last_stop = 'stop'
@@ -173,7 +194,6 @@ def stop_clicked(currentTask):
model_management.interrupt_current_processing()
return currentTask
-
def skip_clicked(currentTask):
import ldm_patched.modules.model_management as model_management
currentTask.last_stop = 'skip'
@@ -181,23 +201,22 @@ def skip_clicked(currentTask):
model_management.interrupt_current_processing()
return currentTask
-
stop_button.click(stop_clicked, inputs=currentTask, outputs=currentTask, queue=False, show_progress=False, _js='cancelGenerateForever')
skip_button.click(skip_clicked, inputs=currentTask, outputs=currentTask, queue=False, show_progress=False)
with gr.Row(elem_classes='advanced_check_row'):
- input_image_checkbox = gr.Checkbox(label='Input Image', value=False, container=False, elem_classes='min_check')
+ input_image_checkbox = gr.Checkbox(label='Input Image', value=modules.config.default_image_prompt_checkbox, container=False, elem_classes='min_check')
enhance_checkbox = gr.Checkbox(label='Enhance', value=modules.config.default_enhance_checkbox, container=False, elem_classes='min_check')
advanced_checkbox = gr.Checkbox(label='Advanced', value=modules.config.default_advanced_checkbox, container=False, elem_classes='min_check')
- with gr.Row(visible=False) as image_input_panel:
- with gr.Tabs():
- with gr.TabItem(label='Upscale or Variation') as uov_tab:
+ with gr.Row(visible=modules.config.default_image_prompt_checkbox) as image_input_panel:
+ with gr.Tabs(selected=modules.config.default_selected_image_input_tab_id):
+ with gr.Tab(label='Upscale or Variation', id='uov_tab') as uov_tab:
with gr.Row():
with gr.Column():
uov_input_image = grh.Image(label='Image', source='upload', type='numpy', show_label=False)
with gr.Column():
- uov_method = gr.Radio(label='Upscale or Variation:', choices=flags.uov_list, value=flags.disabled)
+ uov_method = gr.Radio(label='Upscale or Variation:', choices=flags.uov_list, value=modules.config.default_uov_method)
gr.HTML('\U0001F4D4 Documentation')
- with gr.TabItem(label='Image Prompt') as ip_tab:
+ with gr.Tab(label='Image Prompt', id='ip_tab') as ip_tab:
with gr.Row():
ip_images = []
ip_types = []
@@ -205,49 +224,46 @@ def skip_clicked(currentTask):
ip_weights = []
ip_ctrls = []
ip_ad_cols = []
- for _ in range(flags.controlnet_image_count):
+ for image_count in range(modules.config.default_controlnet_image_count):
+ image_count += 1
with gr.Column():
- ip_image = grh.Image(label='Image', source='upload', type='numpy', show_label=False, height=300)
+ ip_image = grh.Image(label='Image', source='upload', type='numpy', show_label=False, height=300, value=modules.config.default_ip_images[image_count])
ip_images.append(ip_image)
ip_ctrls.append(ip_image)
- with gr.Column(visible=False) as ad_col:
+ with gr.Column(visible=modules.config.default_image_prompt_advanced_checkbox) as ad_col:
with gr.Row():
- default_end, default_weight = flags.default_parameters[flags.default_ip]
-
- ip_stop = gr.Slider(label='Stop At', minimum=0.0, maximum=1.0, step=0.001, value=default_end)
+ ip_stop = gr.Slider(label='Stop At', minimum=0.0, maximum=1.0, step=0.001, value=modules.config.default_ip_stop_ats[image_count])
ip_stops.append(ip_stop)
ip_ctrls.append(ip_stop)
- ip_weight = gr.Slider(label='Weight', minimum=0.0, maximum=2.0, step=0.001, value=default_weight)
+ ip_weight = gr.Slider(label='Weight', minimum=0.0, maximum=2.0, step=0.001, value=modules.config.default_ip_weights[image_count])
ip_weights.append(ip_weight)
ip_ctrls.append(ip_weight)
- ip_type = gr.Radio(label='Type', choices=flags.ip_list, value=flags.default_ip, container=False)
+ ip_type = gr.Radio(label='Type', choices=flags.ip_list, value=modules.config.default_ip_types[image_count], container=False)
ip_types.append(ip_type)
ip_ctrls.append(ip_type)
ip_type.change(lambda x: flags.default_parameters[x], inputs=[ip_type], outputs=[ip_stop, ip_weight], queue=False, show_progress=False)
ip_ad_cols.append(ad_col)
- ip_advanced = gr.Checkbox(label='Advanced', value=False, container=False)
+ ip_advanced = gr.Checkbox(label='Advanced', value=modules.config.default_image_prompt_advanced_checkbox, container=False)
gr.HTML('* \"Image Prompt\" is powered by Fooocus Image Mixture Engine (v1.0.1). \U0001F4D4 Documentation')
-
def ip_advance_checked(x):
return [gr.update(visible=x)] * len(ip_ad_cols) + \
[flags.default_ip] * len(ip_types) + \
[flags.default_parameters[flags.default_ip][0]] * len(ip_stops) + \
[flags.default_parameters[flags.default_ip][1]] * len(ip_weights)
-
ip_advanced.change(ip_advance_checked, inputs=ip_advanced,
outputs=ip_ad_cols + ip_types + ip_stops + ip_weights,
queue=False, show_progress=False)
- with gr.TabItem(label='Inpaint or Outpaint') as inpaint_tab:
+ with gr.Tab(label='Inpaint or Outpaint', id='inpaint_tab') as inpaint_tab:
with gr.Row():
with gr.Column():
inpaint_input_image = grh.Image(label='Image', source='upload', type='numpy', tool='sketch', height=500, brush_color="#FFFFFF", elem_id='inpaint_canvas', show_label=False)
- inpaint_advanced_masking_checkbox = gr.Checkbox(label='Enable Advanced Masking Features', value=False)
+ inpaint_advanced_masking_checkbox = gr.Checkbox(label='Enable Advanced Masking Features', value=modules.config.default_inpaint_advanced_masking_checkbox)
inpaint_mode = gr.Dropdown(choices=modules.flags.inpaint_options, value=modules.config.default_inpaint_method, label='Method')
inpaint_additional_prompt = gr.Textbox(placeholder="Describe what you want to inpaint.", elem_id='inpaint_additional_prompt', label='Inpaint Additional Prompt', visible=False)
outpaint_selections = gr.CheckboxGroup(choices=['Left', 'Right', 'Top', 'Bottom'], value=[], label='Outpaint Direction')
@@ -258,16 +274,16 @@ def ip_advance_checked(x):
gr.HTML('* Powered by Fooocus Inpaint Engine \U0001F4D4 Documentation')
example_inpaint_prompts.click(lambda x: x[0], inputs=example_inpaint_prompts, outputs=inpaint_additional_prompt, show_progress=False, queue=False)
- with gr.Column(visible=False) as inpaint_mask_generation_col:
+ with gr.Column(visible=modules.config.default_inpaint_advanced_masking_checkbox) as inpaint_mask_generation_col:
inpaint_mask_image = grh.Image(label='Mask Upload', source='upload', type='numpy', tool='sketch', height=500, brush_color="#FFFFFF", mask_opacity=1, elem_id='inpaint_mask_canvas')
- invert_mask_checkbox = gr.Checkbox(label='Invert Mask When Generating', value=False)
+ invert_mask_checkbox = gr.Checkbox(label='Invert Mask When Generating', value=modules.config.default_invert_mask_checkbox)
inpaint_mask_model = gr.Dropdown(label='Mask generation model',
choices=flags.inpaint_mask_models,
value=modules.config.default_inpaint_mask_model)
inpaint_mask_cloth_category = gr.Dropdown(label='Cloth category',
- choices=flags.inpaint_mask_cloth_category,
- value=modules.config.default_inpaint_mask_cloth_category,
- visible=False)
+ choices=flags.inpaint_mask_cloth_category,
+ value=modules.config.default_inpaint_mask_cloth_category,
+ visible=False)
inpaint_mask_dino_prompt_text = gr.Textbox(label='Detection prompt', value='', visible=False, info='Use singular whenever possible', placeholder='Describe what you want to detect.')
example_inpaint_mask_dino_prompt_text = gr.Dataset(
samples=modules.config.example_enhance_detection_prompts,
@@ -286,7 +302,6 @@ def ip_advance_checked(x):
inpaint_mask_sam_max_detections = gr.Slider(label="Maximum number of detections", info="Set to 0 to detect all", minimum=0, maximum=10, value=modules.config.default_sam_max_detections, step=1, interactive=True)
generate_mask_button = gr.Button(value='Generate mask from image')
-
def generate_mask(image, mask_model, cloth_category, dino_prompt_text, sam_model, box_threshold, text_threshold, sam_max_detections, dino_erode_or_dilate, dino_debug):
from extras.inpaint_mask import generate_mask_from_image
@@ -321,41 +336,38 @@ def generate_mask(image, mask_model, cloth_category, dino_prompt_text, sam_model
example_inpaint_mask_dino_prompt_text],
queue=False, show_progress=False)
- with gr.TabItem(label='Describe') as desc_tab:
+ with gr.Tab(label='Describe', id='describe_tab') as describe_tab:
with gr.Row():
with gr.Column():
- desc_input_image = grh.Image(label='Image', source='upload', type='numpy', show_label=False)
+ describe_input_image = grh.Image(label='Image', source='upload', type='numpy', show_label=False)
with gr.Column():
- desc_method = gr.Radio(
+ describe_method = gr.Radio(
label='Content Type',
- choices=[flags.desc_type_photo, flags.desc_type_anime],
- value=flags.desc_type_photo)
- desc_btn = gr.Button(value='Describe this Image into Prompt')
- desc_image_size = gr.Textbox(label='Image Size and Recommended Size', elem_id='desc_image_size', visible=False)
+ choices=[flags.describe_type_photo, flags.describe_type_anime],
+ value=flags.describe_type_photo)
+ describe_btn = gr.Button(value='Describe this Image into Prompt')
+ describe_image_size = gr.Textbox(label='Image Size and Recommended Size', elem_id='describe_image_size', visible=False)
gr.HTML('\U0001F4D4 Documentation')
-
def trigger_show_image_properties(image):
value = modules.util.get_image_size_info(image, modules.flags.sdxl_aspect_ratios)
return gr.update(value=value, visible=True)
+ describe_input_image.upload(trigger_show_image_properties, inputs=describe_input_image,
+ outputs=describe_image_size, show_progress=False, queue=False)
- desc_input_image.upload(trigger_show_image_properties, inputs=desc_input_image,
- outputs=desc_image_size, show_progress=False, queue=False)
-
- with gr.TabItem(label='Enhance') as enhance_tab:
+ with gr.Tab(label='Enhance', id='enhance_tab') as enhance_tab:
with gr.Row():
with gr.Column():
enhance_input_image = grh.Image(label='Use with Enhance, skips image generation', source='upload', type='numpy')
gr.HTML('\U0001F4D4 Documentation')
- with gr.TabItem(label='Metadata') as metadata_tab:
+ with gr.Tab(label='Metadata', id='metadata_tab') as metadata_tab:
with gr.Column():
metadata_input_image = grh.Image(label='For images created by Fooocus', source='upload', type='pil')
metadata_json = gr.JSON(label='Metadata')
metadata_import_button = gr.Button(value='Apply Metadata')
-
def trigger_metadata_preview(file):
parameters, metadata_scheme = modules.meta_parser.read_info_from_image(file)
@@ -368,13 +380,12 @@ def trigger_metadata_preview(file):
return results
-
metadata_input_image.upload(trigger_metadata_preview, inputs=metadata_input_image,
outputs=metadata_json, queue=False, show_progress=True)
with gr.Row(visible=modules.config.default_enhance_checkbox) as enhance_input_panel:
with gr.Tabs():
- with gr.TabItem(label='Upscale or Variation'):
+ with gr.Tab(label='Upscale or Variation'):
with gr.Row():
with gr.Column():
enhance_uov_method = gr.Radio(label='Upscale or Variation:', choices=flags.uov_list,
@@ -399,7 +410,7 @@ def trigger_metadata_preview(file):
enhance_inpaint_engine_ctrls = []
enhance_inpaint_update_ctrls = []
for index in range(modules.config.default_enhance_tabs):
- with gr.TabItem(label=f'#{index + 1}') as enhance_tab_item:
+ with gr.Tab(label=f'#{index + 1}') as enhance_tab_item:
enhance_enabled = gr.Checkbox(label='Enable', value=False, elem_classes='min_check',
container=False)
@@ -541,11 +552,11 @@ def trigger_metadata_preview(file):
uov_tab.select(lambda: 'uov', outputs=current_tab, queue=False, _js=down_js, show_progress=False)
inpaint_tab.select(lambda: 'inpaint', outputs=current_tab, queue=False, _js=down_js, show_progress=False)
ip_tab.select(lambda: 'ip', outputs=current_tab, queue=False, _js=down_js, show_progress=False)
- desc_tab.select(lambda: 'desc', outputs=current_tab, queue=False, _js=down_js, show_progress=False)
+ describe_tab.select(lambda: 'desc', outputs=current_tab, queue=False, _js=down_js, show_progress=False)
enhance_tab.select(lambda: 'enhance', outputs=current_tab, queue=False, _js=down_js, show_progress=False)
metadata_tab.select(lambda: 'metadata', outputs=current_tab, queue=False, _js=down_js, show_progress=False)
enhance_checkbox.change(lambda x: gr.update(visible=x), inputs=enhance_checkbox,
- outputs=enhance_input_panel, queue=False, show_progress=False, _js=switch_js)
+ outputs=enhance_input_panel, queue=False, show_progress=False, _js=switch_js)
with gr.Column(scale=1, visible=modules.config.default_advanced_checkbox) as advanced_column:
with gr.Tab(label='Settings'):
@@ -581,13 +592,11 @@ def trigger_metadata_preview(file):
elem_id='negative_prompt',
value=modules.config.default_prompt_negative)
seed_random = gr.Checkbox(label='Random', value=True)
- image_seed = gr.Textbox(label='Seed', value=0, max_lines=1, visible=False) # workaround for https://github.com/gradio-app/gradio/issues/5354
-
+ image_seed = gr.Textbox(label='Seed', value=0, max_lines=1, visible=False) # workaround for https://github.com/gradio-app/gradio/issues/5354
def random_checked(r):
return gr.update(visible=not r)
-
def refresh_seed(r, seed_string):
if r:
return random.randint(constants.MIN_SEED, constants.MAX_SEED)
@@ -600,18 +609,15 @@ def refresh_seed(r, seed_string):
pass
return random.randint(constants.MIN_SEED, constants.MAX_SEED)
-
seed_random.change(random_checked, inputs=[seed_random], outputs=[image_seed],
queue=False, show_progress=False)
-
def update_history_link():
if args_manager.args.disable_image_log:
return gr.update(value='')
return gr.update(value=f'\U0001F4DA History Log')
-
history_link = gr.HTML()
shared.gradio_root.load(update_history_link, outputs=history_link, queue=False, show_progress=False)
@@ -690,9 +696,9 @@ def update_history_link():
value=modules.config.default_sample_sharpness,
info='Higher value means image and texture are sharper.')
gr.HTML('\U0001F4D4 Documentation')
- dev_mode = gr.Checkbox(label='Developer Debug Mode', value=False, container=False)
+ dev_mode = gr.Checkbox(label='Developer Debug Mode', value=modules.config.default_developer_debug_mode_checkbox, container=False)
- with gr.Column(visible=False) as dev_tools:
+ with gr.Column(visible=modules.config.default_developer_debug_mode_checkbox) as dev_tools:
with gr.Tab(label='Debug Tools'):
adm_scaler_positive = gr.Slider(label='Positive ADM Guidance Scaler', minimum=0.1, maximum=3.0,
step=0.001, value=1.5, info='The scaler multiplied to positive ADM (use 1.0 to disable). ')
@@ -710,14 +716,14 @@ def update_history_link():
info='Enabling Fooocus\'s implementation of CFG mimicking for TSNR '
'(effective when real CFG > mimicked CFG).')
clip_skip = gr.Slider(label='CLIP Skip', minimum=1, maximum=flags.clip_skip_max, step=1,
- value=modules.config.default_clip_skip,
- info='Bypass CLIP layers to avoid overfitting (use 1 to not skip any layers, 2 is recommended).')
+ value=modules.config.default_clip_skip,
+ info='Bypass CLIP layers to avoid overfitting (use 1 to not skip any layers, 2 is recommended).')
sampler_name = gr.Dropdown(label='Sampler', choices=flags.sampler_list,
value=modules.config.default_sampler)
scheduler_name = gr.Dropdown(label='Scheduler', choices=flags.scheduler_list,
value=modules.config.default_scheduler)
vae_name = gr.Dropdown(label='VAE', choices=[modules.flags.default_vae] + modules.config.vae_filenames,
- value=modules.config.default_vae, show_label=True)
+ value=modules.config.default_vae, show_label=True)
generate_image_grid = gr.Checkbox(label='Generate Image Grid for Each Batch',
info='(Experimental) This may cause performance problems on some computers and certain internet conditions.',
@@ -751,8 +757,8 @@ def update_history_link():
interactive=not modules.config.default_black_out_nsfw,
info='Disable preview during generation.')
disable_intermediate_results = gr.Checkbox(label='Disable Intermediate Results',
- value=flags.Performance.has_restricted_features(modules.config.default_performance),
- info='Disable intermediate results during generation, only show final gallery.')
+ value=flags.Performance.has_restricted_features(modules.config.default_performance),
+ info='Disable intermediate results during generation, only show final gallery.')
disable_seed_increment = gr.Checkbox(label='Disable seed increment',
info='Disable automatic seed increment when image number is > 1.',
@@ -767,6 +773,10 @@ def update_history_link():
inputs=black_out_nsfw, outputs=disable_preview, queue=False,
show_progress=False)
+ if not args_manager.args.disable_image_log:
+ save_final_enhanced_image_only = gr.Checkbox(label='Save only final enhanced image',
+ value=modules.config.default_save_only_final_enhanced_image)
+
if not args_manager.args.disable_metadata:
save_metadata_to_images = gr.Checkbox(label='Save Metadata to Images', value=modules.config.default_save_metadata_to_images,
info='Adds parameters to generated images allowing manual regeneration.')
@@ -855,20 +865,17 @@ def update_history_link():
freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95)
freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2]
-
def dev_mode_checked(r):
return gr.update(visible=r)
-
dev_mode.change(dev_mode_checked, inputs=[dev_mode], outputs=[dev_tools],
queue=False, show_progress=False)
-
def refresh_files_clicked():
modules.config.update_files()
results = [gr.update(choices=modules.config.model_filenames)]
results += [gr.update(choices=['None'] + modules.config.model_filenames)]
- results += [gr.update(choices=['None'] + modules.config.vae_filenames)]
+ results += [gr.update(choices=[flags.default_vae] + modules.config.vae_filenames)]
if not args_manager.args.disable_preset_selection:
results += [gr.update(choices=modules.config.available_presets)]
for i in range(modules.config.default_max_lora_number):
@@ -876,7 +883,6 @@ def refresh_files_clicked():
gr.update(choices=['None'] + modules.config.lora_filenames), gr.update()]
return results
-
refresh_files_output = [base_model, refiner_model, vae_name]
if not args_manager.args.disable_preset_selection:
refresh_files_output += [preset_selection]
@@ -892,7 +898,7 @@ def refresh_files_clicked():
base_model, refiner_model, refiner_switch, sampler_name, scheduler_name, vae_name,
seed_random, image_seed, inpaint_engine, inpaint_engine_state,
inpaint_mode] + enhance_inpaint_mode_ctrls + [generate_button,
- load_parameter_button] + freeu_ctrls + lora_ctrls
+ load_parameter_button] + freeu_ctrls + lora_ctrls
if not args_manager.args.disable_preset_selection:
def preset_selection_change(preset, is_generating, inpaint_mode):
@@ -929,7 +935,6 @@ def inpaint_engine_state_change(inpaint_engine_version, *args):
return result
-
preset_selection.change(preset_selection_change, inputs=[preset_selection, state_is_generating, inpaint_mode], outputs=load_data_outputs, queue=False, show_progress=True) \
.then(fn=style_sorter.sort_styles, inputs=style_selections, outputs=style_selections, queue=False, show_progress=False) \
.then(lambda: None, _js='()=>{refresh_style_localization();}') \
@@ -993,6 +998,9 @@ def inpaint_engine_state_change(inpaint_engine_version, *args):
ctrls += freeu_ctrls
ctrls += inpaint_ctrls
+ if not args_manager.args.disable_image_log:
+ ctrls += [save_final_enhanced_image_only]
+
if not args_manager.args.disable_metadata:
ctrls += [save_metadata_to_images, metadata_scheme]
@@ -1002,7 +1010,6 @@ def inpaint_engine_state_change(inpaint_engine_version, *args):
enhance_uov_prompt_type]
ctrls += enhance_ctrls
-
def parse_meta(raw_prompt_txt, is_generating):
loaded_json = None
if is_json(raw_prompt_txt):
@@ -1016,12 +1023,10 @@ def parse_meta(raw_prompt_txt, is_generating):
return json.dumps(loaded_json), gr.update(visible=False), gr.update(visible=True)
-
prompt.input(parse_meta, inputs=[prompt, state_is_generating], outputs=[prompt, generate_button, load_parameter_button], queue=False, show_progress=False)
load_parameter_button.click(modules.meta_parser.load_parameter_button_click, inputs=[prompt, state_is_generating, inpaint_mode], outputs=load_data_outputs, queue=False, show_progress=False)
-
def trigger_metadata_import(file, state_is_generating):
parameters, metadata_scheme = modules.meta_parser.read_info_from_image(file)
if parameters is None:
@@ -1033,7 +1038,6 @@ def trigger_metadata_import(file, state_is_generating):
return modules.meta_parser.load_parameter_button_click(parsed_parameters, state_is_generating, inpaint_mode)
-
metadata_import_button.click(trigger_metadata_import, inputs=[metadata_input_image, state_is_generating], outputs=load_data_outputs, queue=False, show_progress=True) \
.then(style_sorter.sort_styles, inputs=style_selections, outputs=style_selections, queue=False, show_progress=False)
@@ -1060,19 +1064,17 @@ def trigger_metadata_import(file, state_is_generating):
gr.Audio(interactive=False, value=notification_file, elem_id='audio_notification', visible=False)
break
-
def trigger_describe(mode, img):
- if mode == flags.desc_type_photo:
+ if mode == flags.describe_type_photo:
from extras.interrogate import default_interrogator as default_interrogator_photo
return default_interrogator_photo(img), ["Fooocus V2", "Fooocus Enhance", "Fooocus Sharp"]
- if mode == flags.desc_type_anime:
+ if mode == flags.describe_type_anime:
from extras.wd14tagger import default_interrogator as default_interrogator_anime
return default_interrogator_anime(img), ["Fooocus V2", "Fooocus Masterpiece"]
return mode, ["Fooocus V2"]
-
- desc_btn.click(trigger_describe, inputs=[desc_method, desc_input_image],
- outputs=[prompt, style_selections], show_progress=True, queue=True)
+ describe_btn.click(trigger_describe, inputs=[describe_method, describe_input_image],
+ outputs=[prompt, style_selections], show_progress=True, queue=True)
if args_manager.args.enable_auto_describe_image:
def trigger_auto_describe(mode, img, prompt):
@@ -1081,13 +1083,11 @@ def trigger_auto_describe(mode, img, prompt):
return trigger_describe(mode, img)
return gr.update(), gr.update()
-
- uov_input_image.upload(trigger_auto_describe, inputs=[desc_method, uov_input_image, prompt],
+ uov_input_image.upload(trigger_auto_describe, inputs=[describe_method, uov_input_image, prompt],
outputs=[prompt, style_selections], show_progress=True, queue=True)
enhance_input_image.upload(lambda: gr.update(value=True), outputs=enhance_checkbox, queue=False, show_progress=False) \
- .then(trigger_auto_describe, inputs=[desc_method, enhance_input_image, prompt], outputs=[prompt, style_selections], show_progress=True, queue=True)
-
+ .then(trigger_auto_describe, inputs=[describe_method, enhance_input_image, prompt], outputs=[prompt, style_selections], show_progress=True, queue=True)
def dump_default_english_config():
from modules.localization import dump_english_config