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:
@@ -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