diff --git a/dev_before_start_script.py b/dev_before_start_script.py index d89da95..0dd3a0a 100644 --- a/dev_before_start_script.py +++ b/dev_before_start_script.py @@ -20,3 +20,4 @@ gr.close_all() # --lora-dir /Users/alexander/Downloads/sd-downloads/lora # --lyco-dir /Users/alexander/Downloads/sd-downloads/lyco # --theme dark +# --mo-debug diff --git a/javascript/main.js b/javascript/main.js index 41f9aa9..d226223 100644 --- a/javascript/main.js +++ b/javascript/main.js @@ -336,6 +336,17 @@ function navigateImportExport(){ return [] } +function navigateDebug(){ + log('Navigate debug screen') + const navObj = { + screen: "debug", + token: generateUUID(), + backstack: populateBackstack() + }; + deliverNavObject(navObj) + return [] +} + function navigateEdit(id) { log('Navigate edit screen for id: ' + id) const navObj = { diff --git a/preload.py b/preload.py index 7c996eb..a8cfc99 100644 --- a/preload.py +++ b/preload.py @@ -1,2 +1,3 @@ def preload(parser): - parser.add_argument("--mo-show-dir-settings", help="Enable models dir change in settings", action='store_true') + parser.add_argument("--mo-show-dir-settings", action='store_true', help="Enable models dir change in settings") + parser.add_argument("--mo-debug", action='store_true', help="Enable Model Organizer Debug Mode") diff --git a/scripts/mo/environment.py b/scripts/mo/environment.py index 333ad0c..7c9ae16 100644 --- a/scripts/mo/environment.py +++ b/scripts/mo/environment.py @@ -70,6 +70,7 @@ class Environment: layout: Callable[[], str] card_width: Callable[[], str] card_height: Callable[[], str] + is_debug_mode_enabled: Callable[[], bool] def is_storage_initialized(self) -> bool: return hasattr(self, 'storage') diff --git a/scripts/mo/ui_debug.py b/scripts/mo/ui_debug.py new file mode 100644 index 0000000..71babb8 --- /dev/null +++ b/scripts/mo/ui_debug.py @@ -0,0 +1,77 @@ +import json +import os + +import gradio as gr + +from scripts.mo.environment import env +from scripts.mo.models import ModelType +from scripts.mo.utils import get_model_files_in_dir, find_preview_file, link_preview + + +def _ui_state_report(): + with gr.Column(): + gr.Button('Generate state report') + + +def _on_local_files_scan_click(): + result = [] + + def search_in_dir(model_type) -> list: + dir_path = env.get_model_path(model_type) + local = [] + files = get_model_files_in_dir(dir_path) + for file in files: + preview_file = find_preview_file(file) + rec = { + 'filename': os.path.basename(file), + 'model_type': model_type.value, + 'path': file, + } + + if preview_file is not None and preview_file: + prev = { + 'preview_filename': os.path.basename(preview_file), + 'preview_path': preview_file, + 'preview_link': link_preview(preview_file) + } + rec.update(prev) + + local.append(rec) + return local + + result.extend(search_in_dir(ModelType.CHECKPOINT)) + result.extend(search_in_dir(ModelType.VAE)) + result.extend(search_in_dir(ModelType.LORA)) + result.extend(search_in_dir(ModelType.HYPER_NETWORK)) + result.extend(search_in_dir(ModelType.EMBEDDING)) + result.extend(search_in_dir(ModelType.LYCORIS)) + + return gr.JSON.update(value=json.dumps(result)) + + +def _ui_local_files(): + with gr.Column(): + scan_button = gr.Button('Scan Local Model files') + + local_files_json = gr.JSON(label='Local files') + + scan_button.click(fn=_on_local_files_scan_click, + outputs=local_files_json) + + +def debug_ui_block(): + with gr.Column(): + with gr.Row(): + gr.Markdown('## Debug') + gr.Markdown('') + gr.Markdown('') + gr.Markdown('') + back_button = gr.Button('Back') + + with gr.Tab('State report'): + _ui_state_report() + + with gr.Tab('Local files'): + _ui_local_files() + + back_button.click(fn=None, _js='navigateBack') diff --git a/scripts/mo/ui_home.py b/scripts/mo/ui_home.py index 6ee4bdb..24adca3 100644 --- a/scripts/mo/ui_home.py +++ b/scripts/mo/ui_home.py @@ -191,19 +191,21 @@ def home_ui_block(): label='state_box', elem_classes='mo-alert-warning', elem_id='mo-home-state-box', - visible=True, + visible=False, interactive=False) gr.Textbox(value=initial_state_json, label='initial_state_box', elem_classes='mo-alert-warning', elem_id='mo-initial-state-box', - visible=True, + visible=False, interactive=False) with gr.Row(): gr.Markdown('## Records list') - gr.Markdown('') + if not env.is_debug_mode_enabled(): + gr.Markdown('') + debug_button = gr.Button('Debug', visible=env.is_debug_mode_enabled()) reload_button = gr.Button('Reload') download_all_button = gr.Button('Download All', visible=False) import_export_button = gr.Button('Import/Export') @@ -249,6 +251,7 @@ def home_ui_block(): state_box.change(_prepare_data, inputs=state_box, outputs=[html_content_widget, record_ids_box, download_all_button, groups_dropdown]) + debug_button.click(fn=None, _js='navigateDebug') download_all_button.click(fn=None, inputs=record_ids_box, _js='navigateDownloadRecordList') import_export_button.click(fn=None, _js='navigateImportExport') add_button.click(fn=None, _js='navigateAdd') diff --git a/scripts/mo/ui_main.py b/scripts/mo/ui_main.py index 599e512..3d691e8 100644 --- a/scripts/mo/ui_main.py +++ b/scripts/mo/ui_main.py @@ -6,6 +6,7 @@ import gradio as gr import scripts.mo.ui_navigation as nav import scripts.mo.ui_styled_html as styled from scripts.mo.environment import env +from scripts.mo.ui_debug import debug_ui_block from scripts.mo.ui_details import details_ui_block from scripts.mo.ui_download import download_ui_block from scripts.mo.ui_edit import edit_ui_block @@ -54,6 +55,7 @@ def on_json_box_change(json_state, home_refresh_token): gr.Column.update(visible=state['is_remove_visible']), gr.Column.update(visible=state['is_download_visible']), gr.Column.update(visible=state['is_import_export_visible']), + gr.Column.update(visible=state['is_debug_visible']), gr.Textbox.update(value=home_refresh_token), gr.Textbox.update(value=state['details_record_id']), @@ -95,6 +97,9 @@ def main_ui_block(): with gr.Column(visible=False) as import_export_block: import_export_ui_block() + with gr.Column(visible=False) as debug_block: + debug_ui_block() + _json_nav_box.change(on_json_box_change, inputs=[_json_nav_box, home_refresh_box], outputs=[home_block, @@ -103,6 +108,7 @@ def main_ui_block(): remove_record_block, download_block, import_export_block, + debug_block, home_refresh_box, details_id_box, diff --git a/scripts/mo/ui_navigation.py b/scripts/mo/ui_navigation.py index f551bc7..ae49065 100644 --- a/scripts/mo/ui_navigation.py +++ b/scripts/mo/ui_navigation.py @@ -8,6 +8,7 @@ _EDIT = 'edit' _REMOVE = 'remove' _DOWNLOAD = 'download' _IMPORT_EXPORT = 'import_export' +_DEBUG = 'debug' _NODE_SCREEN = 'screen' _NODE_RECORD_ID = 'record_id' @@ -76,6 +77,7 @@ def get_nav_state(json_nav) -> dict: 'is_remove_visible': False, 'is_download_visible': False, 'is_import_export_visible': False, + 'is_debug_visible': False, 'details_record_id': '', 'edit_data': {}, 'remove_record_id': '', @@ -119,6 +121,8 @@ def get_nav_state(json_nav) -> dict: elif nav_dict[_NODE_SCREEN] == _IMPORT_EXPORT: state['is_import_export_visible'] = True + elif nav_dict[_NODE_SCREEN] == _DEBUG: + state['is_debug_visible'] = True return state diff --git a/scripts/model_organizer.py b/scripts/model_organizer.py index 6c37c36..75b40f0 100644 --- a/scripts/model_organizer.py +++ b/scripts/model_organizer.py @@ -93,6 +93,8 @@ env.lycoris_path = _lycoris_path env.embeddings_path = lambda: shared.opts.mo_embeddings_path if \ hasattr(shared.opts, 'mo_embeddings_path') and shared.opts.mo_embeddings_path else _default_embeddings_path() +env.is_debug_mode_enabled = lambda: hasattr(shared.cmd_opts, 'mo_debug') and shared.cmd_opts.mo_debug + env.script_dir = scripts.basedir() env.theme = lambda: shared.cmd_opts.theme