diff --git a/args_manager.py b/args_manager.py
index 2c59addb..b1584d8b 100644
--- a/args_manager.py
+++ b/args_manager.py
@@ -1,5 +1,7 @@
import ldm_patched.modules.args_parser as args_parser
+import os
+from tempfile import gettempdir
args_parser.parser.add_argument("--share", action='store_true', help="Set whether to share on Gradio.")
@@ -37,7 +39,11 @@ args_parser.args.always_offload_from_vram = not args_parser.args.disable_offload
if args_parser.args.disable_analytics:
import os
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
+
if args_parser.args.disable_in_browser:
args_parser.args.in_browser = False
+if args_parser.args.temp_path is None:
+ args_parser.args.temp_path = os.path.join(gettempdir(), 'Fooocus')
+
args = args_parser.args
diff --git a/ldm_patched/modules/args_parser.py b/ldm_patched/modules/args_parser.py
index 7ffc4a81..35ddacf3 100644
--- a/ldm_patched/modules/args_parser.py
+++ b/ldm_patched/modules/args_parser.py
@@ -112,10 +112,7 @@ parser.add_argument("--is-windows-embedded-python", action="store_true")
parser.add_argument("--disable-server-info", action="store_true")
-if ldm_patched.modules.options.args_parsing:
- args = parser.parse_args([])
-else:
- args = parser.parse_args([])
+args = parser.parse_args([])
if args.is_windows_embedded_python:
args.in_browser = True
diff --git a/modules/async_worker.py b/modules/async_worker.py
index 3d999cb9..d5c81045 100644
--- a/modules/async_worker.py
+++ b/modules/async_worker.py
@@ -134,6 +134,7 @@ def worker():
performance_selection = args.pop()
aspect_ratios_selection = args.pop()
image_number = args.pop()
+ image_extension = args.pop()
image_seed = args.pop()
sharpness = args.pop()
guidance_scale = args.pop()
@@ -390,6 +391,7 @@ def worker():
progressbar(async_task, 3, 'Processing prompts ...')
tasks = []
+
for i in range(image_number):
task_seed = (seed + i) % (constants.MAX_SEED + 1) # randint is inclusive, % is not
task_rng = random.Random(task_seed) # may bind to inpaint noise in the future
@@ -525,8 +527,8 @@ def worker():
if direct_return:
d = [('Upscale (Fast)', '2x')]
- log(uov_input_image, d)
- yield_result(async_task, uov_input_image, do_not_show_finished_images=True)
+ uov_input_image_path = log(uov_input_image, d, image_extension)
+ yield_result(async_task, uov_input_image_path, do_not_show_finished_images=True)
return
tiled = True
@@ -790,6 +792,7 @@ def worker():
if inpaint_worker.current_task is not None:
imgs = [inpaint_worker.current_task.post_process(x) for x in imgs]
+ img_paths = []
for x in imgs:
d = [
('Prompt', task['log_positive_prompt']),
@@ -816,9 +819,9 @@ def worker():
if n != 'None':
d.append((f'LoRA {li + 1}', f'{n} : {w}'))
d.append(('Version', 'v' + fooocus_version.version))
- log(x, d)
+ img_paths.append(log(x, d, image_extension))
- yield_result(async_task, imgs, do_not_show_finished_images=len(tasks) == 1, progressbar_index=int(15.0 + 85.0 * float((current_task_id + 1) * steps) / float(all_steps)))
+ yield_result(async_task, img_paths, do_not_show_finished_images=len(tasks) == 1, progressbar_index=int(15.0 + 85.0 * float((current_task_id + 1) * steps) / float(all_steps)))
except ldm_patched.modules.model_management.InterruptProcessingException as e:
if async_task.last_stop == 'skip':
print('User skipped')
diff --git a/modules/config.py b/modules/config.py
index 2aa394fa..74222d3b 100644
--- a/modules/config.py
+++ b/modules/config.py
@@ -289,6 +289,11 @@ default_max_image_number = get_config_item_or_set_default(
default_value=32,
validator=lambda x: isinstance(x, int) and x >= 1
)
+default_image_extension = get_config_item_or_set_default(
+ key='default_image_extension',
+ default_value='png',
+ validator=lambda x: x in modules.flags.image_extensions
+)
default_image_number = get_config_item_or_set_default(
key='default_image_number',
default_value=2,
@@ -388,7 +393,6 @@ possible_preset_keys = {
"lora_downloads": "lora_downloads"
}
-
REWRITE_PRESET = False
if REWRITE_PRESET and isinstance(args_manager.args.preset, str):
diff --git a/modules/flags.py b/modules/flags.py
index aa9134e2..98022c0e 100644
--- a/modules/flags.py
+++ b/modules/flags.py
@@ -40,6 +40,8 @@ performance_selections = [
('Extreme Speed (LCM) \U00002223 8 steps, intermediate results disabled', 'Extreme Speed')
]
+image_extensions = ['png', 'jpg', 'webp']
+
inpaint_option_default = 'Inpaint or Outpaint (default)'
inpaint_option_detail = 'Improve Detail (face, hand, eyes, etc.)'
inpaint_option_modify = 'Modify Content (add objects, change background, etc.)'
diff --git a/modules/private_logger.py b/modules/private_logger.py
index 968bd4f5..4d2427ad 100644
--- a/modules/private_logger.py
+++ b/modules/private_logger.py
@@ -6,25 +6,29 @@ import urllib.parse
from PIL import Image
from modules.util import generate_temp_filename
-
+from tempfile import gettempdir
log_cache = {}
-def get_current_html_path():
+def get_current_html_path(image_extension=None):
+ _image_extension = image_extension if image_extension else modules.config.default_image_extension
date_string, local_temp_filename, only_name = generate_temp_filename(folder=modules.config.path_outputs,
- extension='png')
+ extension=_image_extension)
html_name = os.path.join(os.path.dirname(local_temp_filename), 'log.html')
return html_name
-def log(img, dic):
- if args_manager.args.disable_image_log:
- return
-
- date_string, local_temp_filename, only_name = generate_temp_filename(folder=modules.config.path_outputs, extension='png')
+def log(img, dic, image_extension=None) -> str:
+ path_outputs = args_manager.args.temp_path if args_manager.args.disable_image_log else modules.config.path_outputs
+ _image_extension = image_extension if image_extension else modules.config.default_image_extension
+ date_string, local_temp_filename, only_name = generate_temp_filename(folder=path_outputs, extension=_image_extension)
os.makedirs(os.path.dirname(local_temp_filename), exist_ok=True)
Image.fromarray(img).save(local_temp_filename)
+
+ if args_manager.args.disable_image_log:
+ return local_temp_filename
+
html_name = os.path.join(os.path.dirname(local_temp_filename), 'log.html')
css_styles = (
@@ -105,4 +109,4 @@ def log(img, dic):
log_cache[html_name] = middle_part
- return
+ return local_temp_filename
diff --git a/readme.md b/readme.md
index 1c1fd06c..28014365 100644
--- a/readme.md
+++ b/readme.md
@@ -22,6 +22,8 @@ Included adjustments:
* 🐛 https://github.com/lllyasviel/Fooocus/pull/1784 - correctly sort files, display deepest directory level first
* ✨ https://github.com/lllyasviel/Fooocus/pull/1785 - update model Juggernaut XL v6 to v8
* ✨ https://github.com/lllyasviel/Fooocus/pull/1809 - reduce file size of preview images
+* ✨ https://github.com/lllyasviel/Fooocus/pull/1932 - use consistent file name in gradio
+* ✨ https://github.com/lllyasviel/Fooocus/pull/1863 - image extension support (png, jpg, webp)
✨ = new feature
🐛 = bugfix
diff --git a/webui.py b/webui.py
index 039f3dae..4ddf849e 100644
--- a/webui.py
+++ b/webui.py
@@ -74,6 +74,11 @@ def generate_clicked(task):
gr.update(visible=True, value=product)
finished = True
+ # delete Fooocus temp images, only keep gradio temp images
+ if args_manager.args.disable_image_log:
+ for filepath in product:
+ os.remove(filepath)
+
execution_time = time.perf_counter() - execution_start_time
print(f'Total time: {execution_time:.2f} seconds')
return
@@ -243,6 +248,11 @@ with shared.gradio_root:
value=modules.config.default_aspect_ratio, info='width × height',
elem_classes='aspect_ratios')
image_number = gr.Slider(label='Image Number', minimum=1, maximum=modules.config.default_max_image_number, step=1, value=modules.config.default_image_number)
+
+ image_extension = gr.Radio(label='Image Outputs Extension',
+ choices=modules.flags.image_extensions,
+ value=modules.config.default_image_extension)
+
negative_prompt = gr.Textbox(label='Negative Prompt', show_label=True, placeholder="Type prompt here.",
info='Describing what you do not want to see.', lines=2,
elem_id='negative_prompt',
@@ -272,7 +282,7 @@ with shared.gradio_root:
queue=False, show_progress=False)
if not args_manager.args.disable_image_log:
- gr.HTML(f'\U0001F4DA History Log')
+ gr.HTML(f'\U0001F4DA History Log')
with gr.Tab(label='Styles'):
style_sorter.try_load_sorted_styles(
@@ -582,7 +592,9 @@ with shared.gradio_root:
adm_scaler_negative, refiner_switch, refiner_model, sampler_name,
scheduler_name, adaptive_cfg, refiner_swap_method, negative_prompt, disable_intermediate_results
], queue=False, show_progress=False)
-
+
+ image_extension.input(lambda x: gr.update(image_extension=x), inputs=image_extension)
+
advanced_checkbox.change(lambda x: gr.update(visible=x), advanced_checkbox, advanced_column,
queue=False, show_progress=False) \
.then(fn=lambda: None, _js='refresh_grid_delayed', queue=False, show_progress=False)
@@ -622,7 +634,7 @@ with shared.gradio_root:
ctrls = [
currentTask, prompt, negative_prompt, translate_prompts, style_selections,
- performance_selection, aspect_ratios_selection, image_number, image_seed, sharpness, guidance_scale
+ performance_selection, aspect_ratios_selection, image_number, image_extension, image_seed, sharpness, guidance_scale
]
ctrls += [base_model, refiner_model, refiner_switch] + lora_ctrls