Skip to content

Commit b673bfc

Browse files
committed
Merge branch 'load-last-prompt' into moonride-main
2 parents 4c2de2e + 398a751 commit b673bfc

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

modules/path.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import os
22
import json
33

4-
from os.path import exists
54
from modules.model_loader import load_file_from_url
65

6+
77
def load_paths(paths_filename):
88
paths_dict = {
99
'modelfile_path': '../models/checkpoints/',
@@ -20,7 +20,7 @@ def load_paths(paths_filename):
2020
'temp_outputs_path': '../outputs/'
2121
}
2222

23-
if exists(paths_filename):
23+
if os.path.exists(paths_filename):
2424
with open(paths_filename, encoding='utf-8') as paths_file:
2525
try:
2626
paths_obj = json.load(paths_file)
@@ -100,6 +100,7 @@ def get_config_or_set_default(key, default):
100100
'../models/prompt_expansion/fooocus_expansion')
101101

102102
temp_outputs_path = get_config_or_set_default('temp_outputs_path', '../outputs/')
103+
last_prompt_path = os.path.join(temp_outputs_path, 'last_prompt.json')
103104

104105
with open(config_path, "w", encoding="utf-8") as json_file:
105106
json.dump(config_dict, json_file, indent=4)

modules/private_logger.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from PIL import Image
55
from PIL.PngImagePlugin import PngInfo
66
from modules.util import generate_temp_filename
7+
from shutil import copy
78

89

910
def log(img, dic, single_line_number=3, metadata=None, save_metadata_json=False, save_metadata_image=False, keep_input_names=False, input_image_filename=None, output_format='png'):
@@ -15,7 +16,8 @@ def log(img, dic, single_line_number=3, metadata=None, save_metadata_json=False,
1516
with open(json_path, 'w', encoding='utf-8') as json_file:
1617
json_file.write(metadata)
1718
json_file.close()
18-
19+
copy(json_path, modules.path.last_prompt_path)
20+
1921
if output_format == 'png':
2022
if save_metadata_image:
2123
pnginfo = PngInfo()

update_log_mre.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### 2.0.78.4 MRE
22

3+
* Added Load Last Prompt button (contribution from sngazm).
34
* Fixed hangup in Upscale (Fast 2x).
45
* Fixed problems with turning off FreeU in some scenarios.
56

webui.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,20 @@ def load_prompt_handler(_file, *args):
257257
return ctrls
258258

259259

260+
def load_last_prompt_handler(*args):
261+
ctrls = list(args)
262+
if exists(modules.path.last_prompt_path):
263+
with open(modules.path.last_prompt_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+
260274
def load_input_images_handler(files):
261275
return list(map(lambda x: x.name, files)), gr.update(selected=GALLERY_ID_INPUT), gr.update(value=len(files))
262276

@@ -377,7 +391,9 @@ def clear_default_image():
377391
seed_random = gr.Checkbox(label='Random', value=settings['seed_random'])
378392
same_seed_for_all = gr.Checkbox(label='Same seed for all images', value=settings['same_seed_for_all'])
379393
image_seed = gr.Textbox(label='Seed', value=settings['seed'], max_lines=1, visible=not settings['seed_random'])
380-
load_prompt_button = gr.UploadButton(label='Load Prompt', file_count='single', file_types=['.json', '.png', '.jpg'], elem_classes='type_small_row', min_width=0)
394+
with gr.Row():
395+
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)