Skip to content

Commit 398a751

Browse files
committed
Added Load Last Prompt feature
1 parent 0ba74df commit 398a751

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

modules/private_logger.py

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ def log(img, dic, single_line_number=3, metadata=None, save_metadata_json=False,
1515
with open(json_path, 'w', encoding='utf-8') as json_file:
1616
json_file.write(metadata)
1717
json_file.close()
18+
last_path = os.path.dirname(local_temp_filename) + "/../last.json"
19+
with open(last_path, 'w', encoding='utf-8') as json_file:
20+
json_file.write(metadata)
21+
json_file.close()
22+
1823

1924
if output_format == 'png':
2025
if save_metadata_image:

webui.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from modules.ui_gradio_extensions import reload_javascript
2323
from modules.util import get_current_log_path, get_previous_log_path
2424
from modules.auth import auth_enabled, check_auth
25-
from os.path import exists
25+
from os.path import exists, join
2626

2727

2828
GALLERY_ID_INPUT = 0
@@ -256,6 +256,21 @@ def load_prompt_handler(_file, *args):
256256
print('load_prompt_handler, e: ' + str(e))
257257
return ctrls
258258

259+
def load_last_prompt_handler(*args):
260+
ctrls = list(args)
261+
path = join(modules.path.temp_outputs_path, 'last.json')
262+
if exists(path):
263+
with open(path, encoding='utf-8') as json_file:
264+
try:
265+
json_obj = json.load(json_file)
266+
metadata_to_ctrls(json_obj, ctrls)
267+
except Exception as e:
268+
print('load_last_prompt_handler, e: ' + str(e))
269+
finally:
270+
json_file.close()
271+
return ctrls
272+
273+
259274

260275
def load_input_images_handler(files):
261276
return list(map(lambda x: x.name, files)), gr.update(selected=GALLERY_ID_INPUT), gr.update(value=len(files))
@@ -378,6 +393,7 @@ def clear_default_image():
378393
same_seed_for_all = gr.Checkbox(label='Same seed for all images', value=settings['same_seed_for_all'])
379394
image_seed = gr.Textbox(label='Seed', value=settings['seed'], max_lines=1, visible=not settings['seed_random'])
380395
load_prompt_button = gr.UploadButton(label='Load Prompt', file_count='single', file_types=['.json', '.png', '.jpg'], elem_classes='type_small_row', min_width=0)
396+
load_last_prompt_button = gr.Button(label='Load Last Prompt', value='Load Last Prompt', elem_classes='type_small_row', min_width=0)
381397

382398
def get_current_links():
383399
return '<a href="https://github.com/lllyasviel/Fooocus/discussions/117">&#128212; Fooocus Advanced</a>' \
@@ -589,6 +605,8 @@ def verify_input(img2img, canny, depth, gallery_in, gallery_rev, gallery_out):
589605
ctrls += [save_metadata_json, save_metadata_image] + img2img_ctrls + [same_seed_for_all, output_format]
590606
ctrls += canny_ctrls + depth_ctrls + [prompt_expansion] + freeu_ctrls
591607
load_prompt_button.upload(fn=load_prompt_handler, inputs=[load_prompt_button] + ctrls + [seed_random], outputs=ctrls + [seed_random])
608+
load_last_prompt_button.click(fn=load_last_prompt_handler, inputs=ctrls + [seed_random], outputs=ctrls + [seed_random])
609+
592610
ctrls += [input_image_checkbox, current_tab]
593611
ctrls += [uov_method, uov_input_image]
594612
ctrls += [outpaint_selections, inpaint_input_image]

0 commit comments

Comments
 (0)