add local models scan; fix preview links

feature/existing-files-listing
Alexander Sokol 2023-05-25 13:30:17 +03:00
parent e77c17ca09
commit 771ebff708
7 changed files with 48 additions and 13 deletions

View File

@ -0,0 +1,22 @@
import gradio as gr
gr.close_all()
# --disable-console-progressbars
# --no-half-vae
# --disable-safe-unpickle
# --api
# --no-download-sd-model
# --enable-insecure-extension-access
# --skip-version-check
# --skip-python-version-check
# --listen
# --port 3000
# --ui-debug-mode
# --ckpt-dir /Users/alexander/Downloads/sd-downloads/ckpt
# --vae-dir /Users/alexander/Downloads/sd-downloads/vae
# --embeddings-dir /Users/alexander/Downloads/sd-downloads/embeddings
# --hypernetwork-dir /Users/alexander/Downloads/sd-downloads/hypernetworks
# --lora-dir /Users/alexander/Downloads/sd-downloads/lora
# --lyco-dir /Users/alexander/Downloads/sd-downloads/lyco
# --theme dark

View File

@ -1,7 +1,6 @@
// add tinymce
const script = document.createElement('script');
//script.src = 'file=extensions/sd-model-organizer/javascript/tinymce/tinymce.min.js';
script.src = 'https://cdn.tiny.cloud/1/x4uky7gf82jcmseg81ymjdn05edp1yjtulefc66biwztkikf/tinymce/6/tinymce.min.js';
script.src = 'file=extensions/sd-model-organizer/javascript/tinymce/tinymce.min.js';
document.head.appendChild(script);
function findElem(elementId) {
@ -422,19 +421,24 @@ function deliverNavObject(navObj) {
isHomeInitialStateInvoked = false
function invokeHomeInitialStateLoad(){
log('invokeHomeInitialStateLoad')
if(!isHomeInitialStateInvoked){
const initialStateTextArea = findElem('mo-initial-state-box').querySelector('textarea')
const stateTextArea = findElem('mo-home-state-box').querySelector('textarea')
stateTextArea.value = initialStateTextArea.value
const event = new Event('input', {'bubbles': true, "composed": true});
findElem('mo-home-state-box').querySelector('textarea').dispatchEvent(event);
console.log('Initial load state dispatched')
isHomeInitialStateInvoked = true
log('initial home state invoked')
}
return []
}
onUiLoaded(function () {
log("UI loaded")
invokeHomeInitialStateLoad() // TODO On tab opened
homeTab = findElem('mo_home_tab')
intersectionObserver = new IntersectionObserver((entries) => {
if (entries[0].intersectionRatio > 0) invokeHomeInitialStateLoad();
});
intersectionObserver.observe(homeTab);
})

2
preload.py Normal file
View File

@ -0,0 +1,2 @@
def preload(parser):
parser.add_argument("--mo-show-dir-settings", help="Enable models dir change in settings", action='store_true')

1
run.py
View File

@ -1 +0,0 @@
print('Done. ')

View File

@ -65,7 +65,7 @@ def on_json_box_change(json_state, home_refresh_token):
def main_ui_block():
css_styles = _load_mo_css()
with gr.Blocks(css=css_styles) as main_block:
with gr.Blocks(css=css_styles, elem_id='model_organizer_tab') as main_block:
gr.HTML(f'<style>{css_styles}</style>')
if env.is_storage_has_errors():
gr.HTML(styled.alert_danger(env.storage_error))
@ -77,7 +77,7 @@ def main_ui_block():
_json_nav_box = gr.Textbox(value=nav.navigate_home(), label='mo_json_nav_box', elem_id='mo_json_nav_box',
elem_classes='mo-alert-warning', visible=False)
with gr.Column(visible=True) as home_block:
with gr.Column(visible=True, elem_id='mo_home_tab') as home_block:
home_refresh_box = home_ui_block()
with gr.Column(visible=False) as record_details_block:

View File

@ -5,8 +5,8 @@ import scripts.mo.ui_format as ui_format
from scripts.mo.environment import env
from scripts.mo.models import Record, ModelType
_NO_PREVIEW_DARK = 'https://github.com/alexandersokol/sd-model-organizer/raw/master/pic/no-preview-dark.png'
_NO_PREVIEW_LIGHT = 'https://github.com/alexandersokol/sd-model-organizer/raw/master/pic/no-preview-light.png'
_NO_PREVIEW_DARK = 'file=extensions/sd-model-organizer/pic/no-preview-dark-blue.png'
_NO_PREVIEW_LIGHT = 'file=extensions/sd-model-organizer/pic/no-preview-light.png'
def alert_danger(value) -> str:
@ -77,9 +77,9 @@ def _model_type_css_class(model_type: ModelType) -> str:
def _no_preview_image_url() -> str:
if env.theme() == 'dark':
return f'https://github.com/alexandersokol/sd-model-organizer/raw/develop/pic/no-preview-dark-blue.png'
return _NO_PREVIEW_DARK
else:
return f'https://github.com/alexandersokol/sd-model-organizer/raw/master/pic/no-preview-light.png'
return _NO_PREVIEW_LIGHT
def records_table(records: List[Record]) -> str:

View File

@ -98,7 +98,7 @@ env.theme = lambda: shared.cmd_opts.theme
def on_ui_settings():
mo_options = shared.options_section(('mo', 'Model Organizer'), {
opts = {
'mo_layout': OptionInfo(LAYOUT_CARDS, "Layout Type:", gr.Radio,
{"choices": [LAYOUT_CARDS, LAYOUT_TABLE]}),
'mo_card_width': OptionInfo(0, 'Card width (default if 0):'),
@ -106,6 +106,9 @@ def on_ui_settings():
'mo_storage_type': OptionInfo(STORAGE_SQLITE, "Storage Type:", gr.Radio,
{"choices": [STORAGE_SQLITE, STORAGE_FIREBASE]}),
'mo_download_preview': OptionInfo(True, 'Download Preview'),
}
dir_opts = {
'mo_model_path': OptionInfo('', f'Model directory (If empty uses default: {_default_model_path()}):'),
'mo_vae_path': OptionInfo('', f'VAE directory (If empty uses default: {_default_vae_path()}) :'),
'mo_lora_path': OptionInfo('', f'Lora directory (If empty uses default: {_default_lora_path()}):'),
@ -116,7 +119,12 @@ def on_ui_settings():
f'LyCORIS directory (If empty uses default: {_default_lycoris_path()}):'),
'mo_embeddings_path': OptionInfo('', f'Embeddings directory (If empty uses default: '
f'{_default_embeddings_path()}):')
})
}
if hasattr(shared.cmd_opts, 'mo_show_dir_settings') and shared.cmd_opts.mo_show_dir_settings:
opts.update(dir_opts)
mo_options = shared.options_section(('mo', 'Model Organizer'), opts)
shared.options_templates.update(mo_options)
initialize_storage()