mirror of
https://github.com/lllyasviel/Fooocus.git
synced 2026-08-16 13:13:16 +02:00
2.1.808
* Aspect ratios now show aspect ratios. * Added style search. * Added style sorting/ordering/favorites.
This commit is contained in:
@@ -209,7 +209,7 @@ def worker():
|
||||
tiled = False
|
||||
inpaint_worker.current_task = None
|
||||
|
||||
width, height = aspect_ratios_selection.split('×')
|
||||
width, height = aspect_ratios_selection.replace('×', ' ').split(' ')[:2]
|
||||
width, height = int(width), int(height)
|
||||
|
||||
skip_prompt_processing = False
|
||||
|
||||
+12
-3
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
import json
|
||||
import math
|
||||
import args_manager
|
||||
import modules.flags
|
||||
import modules.sdxl_styles
|
||||
@@ -247,6 +248,17 @@ default_aspect_ratio = get_config_item_or_set_default(
|
||||
validator=lambda x: x in available_aspect_ratios
|
||||
)
|
||||
|
||||
|
||||
def add_ratio(x):
|
||||
a, b = x.replace('*', ' ').split(' ')[:2]
|
||||
a, b = int(a), int(b)
|
||||
g = math.gcd(a, b)
|
||||
return f'{a}×{b} <span style="color: grey;"> \U00002223 {a // g}:{b // g}</span>'
|
||||
|
||||
|
||||
default_aspect_ratio = add_ratio(default_aspect_ratio)
|
||||
available_aspect_ratios = [add_ratio(x) for x in available_aspect_ratios]
|
||||
|
||||
with open(config_path, "w", encoding="utf-8") as json_file:
|
||||
json.dump({k: config_dict[k] for k in always_save_keys}, json_file, indent=4)
|
||||
|
||||
@@ -264,9 +276,6 @@ os.makedirs(path_outputs, exist_ok=True)
|
||||
model_filenames = []
|
||||
lora_filenames = []
|
||||
|
||||
available_aspect_ratios = [x.replace('*', '×') for x in available_aspect_ratios]
|
||||
default_aspect_ratio = default_aspect_ratio.replace('*', '×')
|
||||
|
||||
|
||||
def get_model_filenames(folder_path, name_filter=None):
|
||||
return get_files_from_folder(folder_path, ['.pth', '.ckpt', '.bin', '.safetensors', '.fooocus.patch'], name_filter)
|
||||
|
||||
@@ -100,6 +100,18 @@ progress::after {
|
||||
overflow: auto !important;
|
||||
}
|
||||
|
||||
.aspect_ratios label {
|
||||
width: 140px !important;
|
||||
}
|
||||
|
||||
.aspect_ratios label span {
|
||||
white-space: nowrap !important;
|
||||
}
|
||||
|
||||
.aspect_ratios label input {
|
||||
margin-left: -5px !important;
|
||||
}
|
||||
|
||||
'''
|
||||
progress_html = '''
|
||||
<div class="loader-container">
|
||||
|
||||
@@ -2,29 +2,30 @@ import json
|
||||
import os
|
||||
|
||||
|
||||
current_translation = {}
|
||||
localization_root = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'language')
|
||||
|
||||
|
||||
def localization_js(filename):
|
||||
data = {}
|
||||
global current_translation
|
||||
|
||||
if isinstance(filename, str):
|
||||
full_name = os.path.abspath(os.path.join(localization_root, filename + '.json'))
|
||||
if os.path.exists(full_name):
|
||||
try:
|
||||
with open(full_name, encoding='utf-8') as f:
|
||||
data = json.load(f)
|
||||
assert isinstance(data, dict)
|
||||
for k, v in data.items():
|
||||
current_translation = json.load(f)
|
||||
assert isinstance(current_translation, dict)
|
||||
for k, v in current_translation.items():
|
||||
assert isinstance(k, str)
|
||||
assert isinstance(v, str)
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
print(f'Failed to load localization file {full_name}')
|
||||
|
||||
# data = {k: 'XXX' for k in data.keys()} # use this to see if all texts are covered
|
||||
# current_translation = {k: 'XXX' for k in current_translation.keys()} # use this to see if all texts are covered
|
||||
|
||||
return f"window.localization = {json.dumps(data)}"
|
||||
return f"window.localization = {json.dumps(current_translation)}"
|
||||
|
||||
|
||||
def dump_english_config(components):
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import os
|
||||
import gradio as gr
|
||||
import modules.localization as localization
|
||||
import json
|
||||
|
||||
|
||||
all_styles = []
|
||||
|
||||
|
||||
def try_load_sorted_styles(style_names, default_selected):
|
||||
global all_styles
|
||||
|
||||
all_styles = style_names
|
||||
|
||||
try:
|
||||
if os.path.exists('sorted_styles.json'):
|
||||
with open('sorted_styles.json', 'rt', encoding='utf-8') as fp:
|
||||
sorted_styles = json.load(fp)
|
||||
if len(sorted_styles) == len(all_styles):
|
||||
if all(x in all_styles for x in sorted_styles):
|
||||
if all(x in sorted_styles for x in all_styles):
|
||||
all_styles = sorted_styles
|
||||
except Exception as e:
|
||||
print('Load style sorting failed.')
|
||||
print(e)
|
||||
|
||||
unselected = [y for y in all_styles if y not in default_selected]
|
||||
all_styles = default_selected + unselected
|
||||
|
||||
return all_styles
|
||||
|
||||
|
||||
def sort_styles(selected):
|
||||
unselected = [y for y in all_styles if y not in selected]
|
||||
sorted_styles = selected + unselected
|
||||
try:
|
||||
with open('sorted_styles.json', 'wt', encoding='utf-8') as fp:
|
||||
json.dump(sorted_styles, fp, indent=4)
|
||||
except Exception as e:
|
||||
print('Write style sorting failed.')
|
||||
print(e)
|
||||
return gr.CheckboxGroup.update(choices=sorted_styles)
|
||||
|
||||
|
||||
def localization_key(x):
|
||||
return x + localization.current_translation.get(x, '')
|
||||
|
||||
|
||||
def search_styles(selected, query):
|
||||
unselected = [y for y in all_styles if y not in selected]
|
||||
matched = [y for y in unselected if query.lower() in localization_key(y).lower()] if len(query) > 0 else []
|
||||
unmatched = [y for y in unselected if y not in matched]
|
||||
sorted_styles = matched + selected + unmatched
|
||||
return gr.CheckboxGroup.update(choices=sorted_styles)
|
||||
Reference in New Issue
Block a user