mirror of
https://github.com/lllyasviel/Fooocus.git
synced 2026-08-16 13:13:16 +02:00
add config (#619)
* add config * add config * add config * add config * add config * add config * add config * add config
This commit is contained in:
@@ -224,7 +224,13 @@ def refresh_everything(refiner_model_name, base_model_name, loras):
|
||||
refresh_everything(
|
||||
refiner_model_name=modules.path.default_refiner_model_name,
|
||||
base_model_name=modules.path.default_base_model_name,
|
||||
loras=[(modules.path.default_lora_name, 0.5), ('None', 0.5), ('None', 0.5), ('None', 0.5), ('None', 0.5)]
|
||||
loras=[
|
||||
(modules.path.default_lora_name, modules.path.default_lora_weight),
|
||||
('None', modules.path.default_lora_weight),
|
||||
('None', modules.path.default_lora_weight),
|
||||
('None', modules.path.default_lora_weight),
|
||||
('None', modules.path.default_lora_weight)
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -18,10 +18,7 @@ SCHEDULER_NAMES = ["normal", "karras", "exponential", "sgm_uniform", "simple", "
|
||||
SAMPLER_NAMES = KSAMPLER_NAMES + ["ddim", "uni_pc", "uni_pc_bh2"]
|
||||
|
||||
sampler_list = SAMPLER_NAMES
|
||||
default_sampler = 'dpmpp_2m_sde_gpu'
|
||||
|
||||
scheduler_list = SCHEDULER_NAMES
|
||||
default_scheduler = "karras"
|
||||
|
||||
cn_ip = "Image Prompt"
|
||||
cn_canny = "PyraCanny"
|
||||
|
||||
+71
-17
@@ -1,5 +1,8 @@
|
||||
import os
|
||||
import json
|
||||
import modules.flags
|
||||
import modules.sdxl_styles
|
||||
|
||||
from modules.model_loader import load_file_from_url
|
||||
|
||||
|
||||
@@ -16,29 +19,85 @@ except Exception as e:
|
||||
print(e)
|
||||
|
||||
|
||||
def get_config_or_set_default(key, default):
|
||||
def get_dir_or_set_default(key, default_value):
|
||||
global config_dict
|
||||
v = config_dict.get(key, None)
|
||||
if isinstance(v, str) and os.path.exists(v) and os.path.isdir(v):
|
||||
return v
|
||||
else:
|
||||
dp = os.path.abspath(os.path.join(os.path.dirname(__file__), default))
|
||||
dp = os.path.abspath(os.path.join(os.path.dirname(__file__), default_value))
|
||||
os.makedirs(dp, exist_ok=True)
|
||||
config_dict[key] = dp
|
||||
return dp
|
||||
|
||||
|
||||
modelfile_path = get_config_or_set_default('modelfile_path', '../models/checkpoints/')
|
||||
lorafile_path = get_config_or_set_default('lorafile_path', '../models/loras/')
|
||||
vae_approx_path = get_config_or_set_default('vae_approx_path', '../models/vae_approx/')
|
||||
upscale_models_path = get_config_or_set_default('upscale_models_path', '../models/upscale_models/')
|
||||
inpaint_models_path = get_config_or_set_default('inpaint_models_path', '../models/inpaint/')
|
||||
controlnet_models_path = get_config_or_set_default('controlnet_models_path', '../models/controlnet/')
|
||||
clip_vision_models_path = get_config_or_set_default('clip_vision_models_path', '../models/clip_vision/')
|
||||
fooocus_expansion_path = get_config_or_set_default('fooocus_expansion_path',
|
||||
'../models/prompt_expansion/fooocus_expansion')
|
||||
modelfile_path = get_dir_or_set_default('modelfile_path', '../models/checkpoints/')
|
||||
lorafile_path = get_dir_or_set_default('lorafile_path', '../models/loras/')
|
||||
vae_approx_path = get_dir_or_set_default('vae_approx_path', '../models/vae_approx/')
|
||||
upscale_models_path = get_dir_or_set_default('upscale_models_path', '../models/upscale_models/')
|
||||
inpaint_models_path = get_dir_or_set_default('inpaint_models_path', '../models/inpaint/')
|
||||
controlnet_models_path = get_dir_or_set_default('controlnet_models_path', '../models/controlnet/')
|
||||
clip_vision_models_path = get_dir_or_set_default('clip_vision_models_path', '../models/clip_vision/')
|
||||
fooocus_expansion_path = get_dir_or_set_default('fooocus_expansion_path', '../models/prompt_expansion/fooocus_expansion')
|
||||
temp_outputs_path = get_dir_or_set_default('temp_outputs_path', '../outputs/')
|
||||
|
||||
temp_outputs_path = get_config_or_set_default('temp_outputs_path', '../outputs/')
|
||||
|
||||
def get_config_item_or_set_default(key, default_value, validator):
|
||||
global config_dict
|
||||
if key not in config_dict:
|
||||
config_dict[key] = default_value
|
||||
return default_value
|
||||
|
||||
v = config_dict.get(key, None)
|
||||
if v is None or v == '':
|
||||
v = 'None'
|
||||
if validator(v):
|
||||
return v
|
||||
else:
|
||||
config_dict[key] = default_value
|
||||
return default_value
|
||||
|
||||
|
||||
default_base_model_name = get_config_item_or_set_default(
|
||||
key='default_model',
|
||||
default_value='sd_xl_base_1.0_0.9vae.safetensors',
|
||||
validator=lambda x: isinstance(x, str) and os.path.exists(os.path.join(modelfile_path, x))
|
||||
)
|
||||
default_refiner_model_name = get_config_item_or_set_default(
|
||||
key='default_refiner',
|
||||
default_value='sd_xl_refiner_1.0_0.9vae.safetensors',
|
||||
validator=lambda x: x == 'None' or (isinstance(x, str) and os.path.exists(os.path.join(modelfile_path, x)))
|
||||
)
|
||||
default_lora_name = get_config_item_or_set_default(
|
||||
key='default_lora',
|
||||
default_value='sd_xl_offset_example-lora_1.0.safetensors',
|
||||
validator=lambda x: x == 'None' or (isinstance(x, str) and os.path.exists(os.path.join(lorafile_path, x)))
|
||||
)
|
||||
default_lora_weight = get_config_item_or_set_default(
|
||||
key='default_lora_weight',
|
||||
default_value=0.5,
|
||||
validator=lambda x: isinstance(x, float)
|
||||
)
|
||||
default_cfg_scale = get_config_item_or_set_default(
|
||||
key='default_cfg_scale',
|
||||
default_value=7.0,
|
||||
validator=lambda x: isinstance(x, float)
|
||||
)
|
||||
default_sampler = get_config_item_or_set_default(
|
||||
key='default_sampler',
|
||||
default_value='dpmpp_2m_sde_gpu',
|
||||
validator=lambda x: x in modules.flags.sampler_list
|
||||
)
|
||||
default_scheduler = get_config_item_or_set_default(
|
||||
key='default_scheduler',
|
||||
default_value='karras',
|
||||
validator=lambda x: x in modules.flags.scheduler_list
|
||||
)
|
||||
default_styles = get_config_item_or_set_default(
|
||||
key='default_styles',
|
||||
default_value=['Fooocus V2', 'Default (Slightly Cinematic)'],
|
||||
validator=lambda x: isinstance(x, list) and all(y in modules.sdxl_styles.legal_style_names for y in x)
|
||||
)
|
||||
|
||||
with open(config_path, "w", encoding="utf-8") as json_file:
|
||||
json.dump(config_dict, json_file, indent=4)
|
||||
@@ -46,11 +105,6 @@ with open(config_path, "w", encoding="utf-8") as json_file:
|
||||
|
||||
os.makedirs(temp_outputs_path, exist_ok=True)
|
||||
|
||||
default_base_model_name = 'sd_xl_base_1.0_0.9vae.safetensors'
|
||||
default_refiner_model_name = 'sd_xl_refiner_1.0_0.9vae.safetensors'
|
||||
default_lora_name = 'sd_xl_offset_example-lora_1.0.safetensors'
|
||||
default_lora_weight = 0.5
|
||||
|
||||
model_filenames = []
|
||||
lora_filenames = []
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
fooocus_expansion = "Fooocus V2"
|
||||
default_styles = ["Default (Slightly Cinematic)"]
|
||||
|
||||
import modules.path
|
||||
# https://github.com/twri/sdxl_prompt_styler/blob/main/sdxl_styles.json
|
||||
|
||||
styles = [
|
||||
@@ -933,9 +931,11 @@ def normalize_key(k):
|
||||
return k
|
||||
|
||||
|
||||
default_styles = [normalize_key(x) for x in default_styles]
|
||||
styles = {normalize_key(k['name']): (k['prompt'], k['negative_prompt']) for k in styles}
|
||||
style_keys = list(styles.keys())
|
||||
fooocus_expansion = "Fooocus V2"
|
||||
legal_style_names = [fooocus_expansion] + style_keys
|
||||
|
||||
|
||||
SD_XL_BASE_RATIOS = {
|
||||
"0.5": (704, 1408),
|
||||
|
||||
Reference in New Issue
Block a user