Spaces:
Running
on
Zero
Running
on
Zero
Upload folder using huggingface_hub
Browse files- core/settings.py +11 -0
- requirements.txt +6 -4
- ui/events.py +37 -2
- yaml/file_list.yaml +6 -2
- yaml/model_defaults.yaml +17 -0
- yaml/model_list.yaml +6 -1
core/settings.py
CHANGED
|
@@ -17,6 +17,7 @@ _PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
| 17 |
_MODEL_LIST_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'model_list.yaml')
|
| 18 |
_FILE_LIST_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'file_list.yaml')
|
| 19 |
_CONSTANTS_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'constants.yaml')
|
|
|
|
| 20 |
|
| 21 |
|
| 22 |
def load_constants_from_yaml(filepath=_CONSTANTS_PATH):
|
|
@@ -79,6 +80,13 @@ def load_models_from_yaml(model_list_filepath=_MODEL_LIST_PATH, download_map=Non
|
|
| 79 |
|
| 80 |
return model_maps
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
try:
|
| 83 |
ALL_FILE_DOWNLOAD_MAP = load_file_download_map()
|
| 84 |
loaded_maps = load_models_from_yaml(download_map=ALL_FILE_DOWNLOAD_MAP)
|
|
@@ -86,12 +94,15 @@ try:
|
|
| 86 |
ALL_MODEL_MAP = loaded_maps["ALL_MODEL_MAP"]
|
| 87 |
|
| 88 |
MODEL_TYPE_MAP = {k: v[2] for k, v in ALL_MODEL_MAP.items()}
|
|
|
|
|
|
|
| 89 |
|
| 90 |
except Exception as e:
|
| 91 |
print(f"FATAL: Could not load model configuration from YAML. Error: {e}")
|
| 92 |
ALL_FILE_DOWNLOAD_MAP = {}
|
| 93 |
MODEL_MAP_CHECKPOINT, ALL_MODEL_MAP = {}, {}
|
| 94 |
MODEL_TYPE_MAP = {}
|
|
|
|
| 95 |
|
| 96 |
|
| 97 |
try:
|
|
|
|
| 17 |
_MODEL_LIST_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'model_list.yaml')
|
| 18 |
_FILE_LIST_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'file_list.yaml')
|
| 19 |
_CONSTANTS_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'constants.yaml')
|
| 20 |
+
_MODEL_DEFAULTS_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'model_defaults.yaml')
|
| 21 |
|
| 22 |
|
| 23 |
def load_constants_from_yaml(filepath=_CONSTANTS_PATH):
|
|
|
|
| 80 |
|
| 81 |
return model_maps
|
| 82 |
|
| 83 |
+
def load_model_defaults(filepath=_MODEL_DEFAULTS_PATH):
|
| 84 |
+
if not os.path.exists(filepath):
|
| 85 |
+
print(f"Warning: Model defaults file not found at {filepath}. Using empty defaults.")
|
| 86 |
+
return {}
|
| 87 |
+
with open(filepath, 'r', encoding='utf-8') as f:
|
| 88 |
+
return yaml.safe_load(f)
|
| 89 |
+
|
| 90 |
try:
|
| 91 |
ALL_FILE_DOWNLOAD_MAP = load_file_download_map()
|
| 92 |
loaded_maps = load_models_from_yaml(download_map=ALL_FILE_DOWNLOAD_MAP)
|
|
|
|
| 94 |
ALL_MODEL_MAP = loaded_maps["ALL_MODEL_MAP"]
|
| 95 |
|
| 96 |
MODEL_TYPE_MAP = {k: v[2] for k, v in ALL_MODEL_MAP.items()}
|
| 97 |
+
|
| 98 |
+
ALL_MODEL_DEFAULTS = load_model_defaults()
|
| 99 |
|
| 100 |
except Exception as e:
|
| 101 |
print(f"FATAL: Could not load model configuration from YAML. Error: {e}")
|
| 102 |
ALL_FILE_DOWNLOAD_MAP = {}
|
| 103 |
MODEL_MAP_CHECKPOINT, ALL_MODEL_MAP = {}, {}
|
| 104 |
MODEL_TYPE_MAP = {}
|
| 105 |
+
ALL_MODEL_DEFAULTS = {}
|
| 106 |
|
| 107 |
|
| 108 |
try:
|
requirements.txt
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
-
comfyui-frontend-package==1.
|
| 2 |
-
comfyui-workflow-templates==0.
|
| 3 |
-
comfyui-embedded-docs==0.
|
| 4 |
-
torch
|
| 5 |
torchsde
|
| 6 |
torchvision
|
| 7 |
torchaudio
|
|
@@ -21,6 +21,8 @@ psutil
|
|
| 21 |
alembic
|
| 22 |
SQLAlchemy
|
| 23 |
av>=14.2.0
|
|
|
|
|
|
|
| 24 |
|
| 25 |
#non essential dependencies:
|
| 26 |
kornia>=0.7.1
|
|
|
|
| 1 |
+
comfyui-frontend-package==1.37.11
|
| 2 |
+
comfyui-workflow-templates==0.8.24
|
| 3 |
+
comfyui-embedded-docs==0.4.0
|
| 4 |
+
torch==2.9.1
|
| 5 |
torchsde
|
| 6 |
torchvision
|
| 7 |
torchaudio
|
|
|
|
| 21 |
alembic
|
| 22 |
SQLAlchemy
|
| 23 |
av>=14.2.0
|
| 24 |
+
comfy-kitchen>=0.2.7
|
| 25 |
+
requests
|
| 26 |
|
| 27 |
#non essential dependencies:
|
| 28 |
kornia>=0.7.1
|
ui/events.py
CHANGED
|
@@ -41,6 +41,32 @@ def load_diffsynth_controlnet_config():
|
|
| 41 |
print(f"Error loading diffsynth_controlnet_models.yaml: {e}")
|
| 42 |
return []
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
def attach_event_handlers(ui_components, demo):
|
| 46 |
def update_cn_input_visibility(choice):
|
|
@@ -533,6 +559,17 @@ def attach_event_handlers(ui_components, demo):
|
|
| 533 |
("txt2img", "txt2img"), ("img2img", "img2img"), ("inpaint", "inpaint"),
|
| 534 |
("outpaint", "outpaint"), ("hires_fix", "hires_fix"),
|
| 535 |
]:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 536 |
if f'add_lora_button_{prefix}' in ui_components:
|
| 537 |
create_lora_event_handlers(prefix)
|
| 538 |
lora_uploads = ui_components[f'lora_uploads_{prefix}']
|
|
@@ -612,7 +649,6 @@ def attach_event_handlers(ui_components, demo):
|
|
| 612 |
ui_components['view_mode_inpaint'].change(fn=toggle_inpaint_fullscreen_view, inputs=[ui_components['view_mode_inpaint']], outputs=output_components, show_progress=False)
|
| 613 |
|
| 614 |
def initialize_all_cn_dropdowns():
|
| 615 |
-
# Standard ControlNet
|
| 616 |
cn_config = load_controlnet_config()
|
| 617 |
cn_updates = {}
|
| 618 |
if cn_config:
|
|
@@ -634,7 +670,6 @@ def attach_event_handlers(ui_components, demo):
|
|
| 634 |
for series_dd in ui_components[f'controlnet_series_{prefix}']: cn_updates[series_dd] = gr.update(choices=series_choices, value=default_series)
|
| 635 |
for filepath_state in ui_components[f'controlnet_filepaths_{prefix}']: cn_updates[filepath_state] = filepath
|
| 636 |
|
| 637 |
-
# DiffSynth ControlNet
|
| 638 |
diffsynth_cn_config = load_diffsynth_controlnet_config()
|
| 639 |
diffsynth_updates = {}
|
| 640 |
if diffsynth_cn_config:
|
|
|
|
| 41 |
print(f"Error loading diffsynth_controlnet_models.yaml: {e}")
|
| 42 |
return []
|
| 43 |
|
| 44 |
+
def on_model_change(model_display_name):
|
| 45 |
+
"""
|
| 46 |
+
Callback function to update UI elements when the base model changes.
|
| 47 |
+
It loads default values for steps and cfg from model_defaults.yaml.
|
| 48 |
+
"""
|
| 49 |
+
defaults = ALL_MODEL_DEFAULTS.get('Default', {}).copy()
|
| 50 |
+
|
| 51 |
+
model_found = False
|
| 52 |
+
for category, models_in_category in ALL_MODEL_DEFAULTS.items():
|
| 53 |
+
if category == 'Default' or not isinstance(models_in_category, dict):
|
| 54 |
+
continue
|
| 55 |
+
|
| 56 |
+
if model_display_name in models_in_category:
|
| 57 |
+
if '_defaults' in models_in_category:
|
| 58 |
+
defaults.update(models_in_category['_defaults'])
|
| 59 |
+
defaults.update(models_in_category[model_display_name])
|
| 60 |
+
model_found = True
|
| 61 |
+
break
|
| 62 |
+
|
| 63 |
+
if not model_found:
|
| 64 |
+
print(f"No specific defaults found for '{model_display_name}'. Using category or global defaults.")
|
| 65 |
+
|
| 66 |
+
steps_update = gr.update(value=defaults.get('steps'))
|
| 67 |
+
cfg_update = gr.update(value=defaults.get('cfg'))
|
| 68 |
+
|
| 69 |
+
return steps_update, cfg_update
|
| 70 |
|
| 71 |
def attach_event_handlers(ui_components, demo):
|
| 72 |
def update_cn_input_visibility(choice):
|
|
|
|
| 559 |
("txt2img", "txt2img"), ("img2img", "img2img"), ("inpaint", "inpaint"),
|
| 560 |
("outpaint", "outpaint"), ("hires_fix", "hires_fix"),
|
| 561 |
]:
|
| 562 |
+
model_dropdown = ui_components.get(f'base_model_{prefix}')
|
| 563 |
+
steps_slider = ui_components.get(f'steps_{prefix}')
|
| 564 |
+
cfg_slider = ui_components.get(f'cfg_{prefix}')
|
| 565 |
+
if all([model_dropdown, steps_slider, cfg_slider]):
|
| 566 |
+
model_dropdown.change(
|
| 567 |
+
fn=on_model_change,
|
| 568 |
+
inputs=[model_dropdown],
|
| 569 |
+
outputs=[steps_slider, cfg_slider],
|
| 570 |
+
show_progress=False
|
| 571 |
+
)
|
| 572 |
+
|
| 573 |
if f'add_lora_button_{prefix}' in ui_components:
|
| 574 |
create_lora_event_handlers(prefix)
|
| 575 |
lora_uploads = ui_components[f'lora_uploads_{prefix}']
|
|
|
|
| 649 |
ui_components['view_mode_inpaint'].change(fn=toggle_inpaint_fullscreen_view, inputs=[ui_components['view_mode_inpaint']], outputs=output_components, show_progress=False)
|
| 650 |
|
| 651 |
def initialize_all_cn_dropdowns():
|
|
|
|
| 652 |
cn_config = load_controlnet_config()
|
| 653 |
cn_updates = {}
|
| 654 |
if cn_config:
|
|
|
|
| 670 |
for series_dd in ui_components[f'controlnet_series_{prefix}']: cn_updates[series_dd] = gr.update(choices=series_choices, value=default_series)
|
| 671 |
for filepath_state in ui_components[f'controlnet_filepaths_{prefix}']: cn_updates[filepath_state] = filepath
|
| 672 |
|
|
|
|
| 673 |
diffsynth_cn_config = load_diffsynth_controlnet_config()
|
| 674 |
diffsynth_updates = {}
|
| 675 |
if diffsynth_cn_config:
|
yaml/file_list.yaml
CHANGED
|
@@ -4,12 +4,16 @@ file:
|
|
| 4 |
source: "hf"
|
| 5 |
repo_id: "Comfy-Org/z_image_turbo"
|
| 6 |
repository_file_path: "split_files/diffusion_models/z_image_turbo_bf16.safetensors"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
text_encoders:
|
| 9 |
-
- filename: "
|
| 10 |
source: "hf"
|
| 11 |
repo_id: "Comfy-Org/z_image_turbo"
|
| 12 |
-
repository_file_path: "split_files/text_encoders/
|
| 13 |
|
| 14 |
vae:
|
| 15 |
- filename: "ae.safetensors"
|
|
|
|
| 4 |
source: "hf"
|
| 5 |
repo_id: "Comfy-Org/z_image_turbo"
|
| 6 |
repository_file_path: "split_files/diffusion_models/z_image_turbo_bf16.safetensors"
|
| 7 |
+
- filename: "z_image_bf16.safetensors"
|
| 8 |
+
source: "hf"
|
| 9 |
+
repo_id: "Comfy-Org/z_image"
|
| 10 |
+
repository_file_path: "split_files/diffusion_models/z_image_bf16.safetensors"
|
| 11 |
|
| 12 |
text_encoders:
|
| 13 |
+
- filename: "qwen_3_4b_fp8_mixed.safetensors"
|
| 14 |
source: "hf"
|
| 15 |
repo_id: "Comfy-Org/z_image_turbo"
|
| 16 |
+
repository_file_path: "split_files/text_encoders/qwen_3_4b_fp8_mixed.safetensors"
|
| 17 |
|
| 18 |
vae:
|
| 19 |
- filename: "ae.safetensors"
|
yaml/model_defaults.yaml
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Default:
|
| 2 |
+
steps: 25
|
| 3 |
+
cfg: 4.0
|
| 4 |
+
sampler_name: "res_multistep"
|
| 5 |
+
scheduler: "simple"
|
| 6 |
+
|
| 7 |
+
Z-Image:
|
| 8 |
+
_defaults:
|
| 9 |
+
steps: 25
|
| 10 |
+
cfg: 4.0
|
| 11 |
+
sampler_name: "res_multistep"
|
| 12 |
+
scheduler: "simple"
|
| 13 |
+
"Tongyi-MAI/Z Image Turbo":
|
| 14 |
+
steps: 9
|
| 15 |
+
cfg: 1.0
|
| 16 |
+
sampler_name: "res_multistep"
|
| 17 |
+
scheduler: "simple"
|
yaml/model_list.yaml
CHANGED
|
@@ -3,4 +3,9 @@ Checkpoint:
|
|
| 3 |
components:
|
| 4 |
unet: "z_image_turbo_bf16.safetensors"
|
| 5 |
vae: "ae.safetensors"
|
| 6 |
-
clip: "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
components:
|
| 4 |
unet: "z_image_turbo_bf16.safetensors"
|
| 5 |
vae: "ae.safetensors"
|
| 6 |
+
clip: "qwen_3_4b_fp8_mixed.safetensors"
|
| 7 |
+
- display_name: "Tongyi-MAI/Z Image"
|
| 8 |
+
components:
|
| 9 |
+
unet: "z_image_bf16.safetensors"
|
| 10 |
+
vae: "ae.safetensors"
|
| 11 |
+
clip: "qwen_3_4b_fp8_mixed.safetensors"
|