add debug screen
parent
771ebff708
commit
77cd631f02
|
|
@ -20,3 +20,4 @@ gr.close_all()
|
||||||
# --lora-dir /Users/alexander/Downloads/sd-downloads/lora
|
# --lora-dir /Users/alexander/Downloads/sd-downloads/lora
|
||||||
# --lyco-dir /Users/alexander/Downloads/sd-downloads/lyco
|
# --lyco-dir /Users/alexander/Downloads/sd-downloads/lyco
|
||||||
# --theme dark
|
# --theme dark
|
||||||
|
# --mo-debug
|
||||||
|
|
|
||||||
|
|
@ -336,6 +336,17 @@ function navigateImportExport(){
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function navigateDebug(){
|
||||||
|
log('Navigate debug screen')
|
||||||
|
const navObj = {
|
||||||
|
screen: "debug",
|
||||||
|
token: generateUUID(),
|
||||||
|
backstack: populateBackstack()
|
||||||
|
};
|
||||||
|
deliverNavObject(navObj)
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
function navigateEdit(id) {
|
function navigateEdit(id) {
|
||||||
log('Navigate edit screen for id: ' + id)
|
log('Navigate edit screen for id: ' + id)
|
||||||
const navObj = {
|
const navObj = {
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
def preload(parser):
|
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")
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,7 @@ class Environment:
|
||||||
layout: Callable[[], str]
|
layout: Callable[[], str]
|
||||||
card_width: Callable[[], str]
|
card_width: Callable[[], str]
|
||||||
card_height: Callable[[], str]
|
card_height: Callable[[], str]
|
||||||
|
is_debug_mode_enabled: Callable[[], bool]
|
||||||
|
|
||||||
def is_storage_initialized(self) -> bool:
|
def is_storage_initialized(self) -> bool:
|
||||||
return hasattr(self, 'storage')
|
return hasattr(self, 'storage')
|
||||||
|
|
|
||||||
|
|
@ -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')
|
||||||
|
|
@ -191,19 +191,21 @@ def home_ui_block():
|
||||||
label='state_box',
|
label='state_box',
|
||||||
elem_classes='mo-alert-warning',
|
elem_classes='mo-alert-warning',
|
||||||
elem_id='mo-home-state-box',
|
elem_id='mo-home-state-box',
|
||||||
visible=True,
|
visible=False,
|
||||||
interactive=False)
|
interactive=False)
|
||||||
|
|
||||||
gr.Textbox(value=initial_state_json,
|
gr.Textbox(value=initial_state_json,
|
||||||
label='initial_state_box',
|
label='initial_state_box',
|
||||||
elem_classes='mo-alert-warning',
|
elem_classes='mo-alert-warning',
|
||||||
elem_id='mo-initial-state-box',
|
elem_id='mo-initial-state-box',
|
||||||
visible=True,
|
visible=False,
|
||||||
interactive=False)
|
interactive=False)
|
||||||
|
|
||||||
with gr.Row():
|
with gr.Row():
|
||||||
gr.Markdown('## Records list')
|
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')
|
reload_button = gr.Button('Reload')
|
||||||
download_all_button = gr.Button('Download All', visible=False)
|
download_all_button = gr.Button('Download All', visible=False)
|
||||||
import_export_button = gr.Button('Import/Export')
|
import_export_button = gr.Button('Import/Export')
|
||||||
|
|
@ -249,6 +251,7 @@ def home_ui_block():
|
||||||
state_box.change(_prepare_data, inputs=state_box,
|
state_box.change(_prepare_data, inputs=state_box,
|
||||||
outputs=[html_content_widget, record_ids_box, download_all_button, groups_dropdown])
|
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')
|
download_all_button.click(fn=None, inputs=record_ids_box, _js='navigateDownloadRecordList')
|
||||||
import_export_button.click(fn=None, _js='navigateImportExport')
|
import_export_button.click(fn=None, _js='navigateImportExport')
|
||||||
add_button.click(fn=None, _js='navigateAdd')
|
add_button.click(fn=None, _js='navigateAdd')
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import gradio as gr
|
||||||
import scripts.mo.ui_navigation as nav
|
import scripts.mo.ui_navigation as nav
|
||||||
import scripts.mo.ui_styled_html as styled
|
import scripts.mo.ui_styled_html as styled
|
||||||
from scripts.mo.environment import env
|
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_details import details_ui_block
|
||||||
from scripts.mo.ui_download import download_ui_block
|
from scripts.mo.ui_download import download_ui_block
|
||||||
from scripts.mo.ui_edit import edit_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_remove_visible']),
|
||||||
gr.Column.update(visible=state['is_download_visible']),
|
gr.Column.update(visible=state['is_download_visible']),
|
||||||
gr.Column.update(visible=state['is_import_export_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=home_refresh_token),
|
||||||
gr.Textbox.update(value=state['details_record_id']),
|
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:
|
with gr.Column(visible=False) as import_export_block:
|
||||||
import_export_ui_block()
|
import_export_ui_block()
|
||||||
|
|
||||||
|
with gr.Column(visible=False) as debug_block:
|
||||||
|
debug_ui_block()
|
||||||
|
|
||||||
_json_nav_box.change(on_json_box_change,
|
_json_nav_box.change(on_json_box_change,
|
||||||
inputs=[_json_nav_box, home_refresh_box],
|
inputs=[_json_nav_box, home_refresh_box],
|
||||||
outputs=[home_block,
|
outputs=[home_block,
|
||||||
|
|
@ -103,6 +108,7 @@ def main_ui_block():
|
||||||
remove_record_block,
|
remove_record_block,
|
||||||
download_block,
|
download_block,
|
||||||
import_export_block,
|
import_export_block,
|
||||||
|
debug_block,
|
||||||
|
|
||||||
home_refresh_box,
|
home_refresh_box,
|
||||||
details_id_box,
|
details_id_box,
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ _EDIT = 'edit'
|
||||||
_REMOVE = 'remove'
|
_REMOVE = 'remove'
|
||||||
_DOWNLOAD = 'download'
|
_DOWNLOAD = 'download'
|
||||||
_IMPORT_EXPORT = 'import_export'
|
_IMPORT_EXPORT = 'import_export'
|
||||||
|
_DEBUG = 'debug'
|
||||||
|
|
||||||
_NODE_SCREEN = 'screen'
|
_NODE_SCREEN = 'screen'
|
||||||
_NODE_RECORD_ID = 'record_id'
|
_NODE_RECORD_ID = 'record_id'
|
||||||
|
|
@ -76,6 +77,7 @@ def get_nav_state(json_nav) -> dict:
|
||||||
'is_remove_visible': False,
|
'is_remove_visible': False,
|
||||||
'is_download_visible': False,
|
'is_download_visible': False,
|
||||||
'is_import_export_visible': False,
|
'is_import_export_visible': False,
|
||||||
|
'is_debug_visible': False,
|
||||||
'details_record_id': '',
|
'details_record_id': '',
|
||||||
'edit_data': {},
|
'edit_data': {},
|
||||||
'remove_record_id': '',
|
'remove_record_id': '',
|
||||||
|
|
@ -119,6 +121,8 @@ def get_nav_state(json_nav) -> dict:
|
||||||
|
|
||||||
elif nav_dict[_NODE_SCREEN] == _IMPORT_EXPORT:
|
elif nav_dict[_NODE_SCREEN] == _IMPORT_EXPORT:
|
||||||
state['is_import_export_visible'] = True
|
state['is_import_export_visible'] = True
|
||||||
|
elif nav_dict[_NODE_SCREEN] == _DEBUG:
|
||||||
|
state['is_debug_visible'] = True
|
||||||
|
|
||||||
return state
|
return state
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,8 @@ env.lycoris_path = _lycoris_path
|
||||||
env.embeddings_path = lambda: shared.opts.mo_embeddings_path if \
|
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()
|
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.script_dir = scripts.basedir()
|
||||||
env.theme = lambda: shared.cmd_opts.theme
|
env.theme = lambda: shared.cmd_opts.theme
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue