persist hf and civitai tokens

Signed-off-by: Vladimir Mandic <mandic00@live.com>
This commit is contained in:
Vladimir Mandic
2025-02-10 08:47:57 -05:00
parent a671501bff
commit 92e7e74d00
4 changed files with 28 additions and 10 deletions
+3 -1
View File
@@ -1,6 +1,6 @@
# Change Log for SD.Next
## Update for 2025-02-09
## Update for 2025-02-10
- **User Interface**
- **Hints**
@@ -29,6 +29,8 @@
allows for configurable image tiling for x/y axis separately
enable in *scripts -> asymmetric tiling*
*note*: traditional symmetric tiling is achieved by setting circular mode for both x and y
- persist *models -> hugginface -> token*
- persist *models -> civitai -> token*
- **Fixes**
- docs/wiki always use relative links
- ui use correct timezone for log display
+3 -1
View File
@@ -110,6 +110,8 @@ def download_civit_model_thread(model_name: str, model_url: str, model_path: str
if os.path.isfile(temp_file):
starting_pos = os.path.getsize(temp_file)
headers['Range'] = f'bytes={starting_pos}-'
if token is None:
token = shared.opts.civit_token
if token is not None and len(token) > 0:
headers['Authorization'] = f'Bearer {token}'
@@ -396,7 +398,7 @@ def load_civitai(model: str, url: str):
return name # already downloaded
else:
shared.log.debug(f'Reference download start: model="{name}"')
download_civit_model_thread(model_name=model, model_url=url, model_path='', model_type='safetensors', token=None)
download_civit_model_thread(model_name=model, model_url=url, model_path='', model_type='safetensors', token=shared.opts.civit_token)
shared.log.debug(f'Reference download complete: model="{name}"')
sd_models.list_models()
info = sd_models.get_closet_checkpoint_match(name)
+8 -6
View File
@@ -359,13 +359,10 @@ def temp_disable_extensions():
]
disable_original = []
disabled = []
if modules.shared.cmd_opts.theme is not None:
theme_name = modules.shared.cmd_opts.theme
if cmd_opts.theme is not None:
theme_name = cmd_opts.theme
else:
theme_name = f'{modules.shared.opts.theme_type.lower()}/{modules.shared.opts.gradio_theme}'
if modules.shared.cmd_opts.locale is not None:
modules.shared.opts.ui_locale = modules.shared.cmd_opts.locale
theme_name = f'{opts.theme_type.lower()}/{opts.gradio_theme}'
if theme_name == 'lobe':
disable_themes.remove('sd-webui-lobe-theme')
elif theme_name == 'cozy-nest' or theme_name == 'cozy':
@@ -948,6 +945,7 @@ options_templates.update(options_section(('huggingface', "Huggingface"), {
"diffusers_model_load_variant": OptionInfo("default", "Preferred Model variant", gr.Radio, {"choices": ['default', 'fp32', 'fp16']}),
"diffusers_vae_load_variant": OptionInfo("default", "Preferred VAE variant", gr.Radio, {"choices": ['default', 'fp32', 'fp16']}),
"custom_diffusers_pipeline": OptionInfo('', 'Load custom Diffusers pipeline'),
"civitai_token": OptionInfo('', 'HuggingFace token', gr.Textbox, {"lines": 2, "visible": False}),
}))
options_templates.update(options_section(('extra_networks', "Networks"), {
@@ -1114,6 +1112,8 @@ class Options:
return data_label.default if data_label is not None else None
def save_atomic(self, filename=None, silent=False):
if self.filename is None:
self.filename = config_filename
if filename is None:
filename = self.filename
if cmd_opts.freeze:
@@ -1234,6 +1234,8 @@ opts = Options()
config_filename = cmd_opts.config
opts.load(config_filename)
cmd_opts = cmd_args.settings_args(opts, cmd_opts)
if cmd_opts.locale is not None:
opts.data['ui_locale'] = cmd_opts.locale
if cmd_opts.use_xformers:
opts.data['cross_attention_optimization'] = 'xFormers'
opts.data['uni_pc_lower_order_final'] = opts.schedulers_use_loworder # compatibility
+14 -2
View File
@@ -429,6 +429,11 @@ def create_ui():
log.info(f'Diffuser model downloaded: model="{hub_id}"')
return f'Diffuser model downloaded: model="{hub_id}"'
def hf_update_token(token):
log.debug('Huggingface update token')
opts.huggingface_token = token
opts.save()
with gr.Column(scale=6):
gr.HTML('<h2>Search for models</h2>Select a model from the search results to download<br><br>')
with gr.Row():
@@ -443,7 +448,7 @@ def create_ui():
hf_variant = gr.Textbox('', label='Specify model variant', placeholder='')
hf_revision = gr.Textbox('', label='Specify model revision', placeholder='')
with gr.Row():
hf_token = gr.Textbox('', label='Huggingface token', placeholder='optional access token for private or gated models')
hf_token = gr.Textbox(opts.huggingface_token, label='Huggingface token', placeholder='optional access token for private or gated models')
hf_mirror = gr.Textbox('', label='Huggingface mirror', placeholder='optional mirror site for downloads')
hf_custom_pipeline = gr.Textbox('', label='Custom pipeline', placeholder='optional pipeline for downloads')
with gr.Column(scale=1):
@@ -459,6 +464,7 @@ def create_ui():
hf_search_btn.click(fn=hf_search, inputs=[hf_search_text], outputs=[hf_results])
hf_results.select(fn=hf_select, inputs=[hf_results], outputs=[hf_selected])
hf_download_model_btn.click(fn=hf_download_model, inputs=[hf_selected, hf_token, hf_variant, hf_revision, hf_mirror, hf_custom_pipeline], outputs=[models_outcome])
hf_token.change(fn=hf_update_token, inputs=[hf_token], outputs=[])
with gr.Tab(label="CivitAI"):
data = []
@@ -632,6 +638,11 @@ def create_ui():
global search_metadata_civit # pylint: disable=global-statement
search_metadata_civit = civit_search_metadata
def civitai_update_token(token):
log.debug('CivitAI update token')
opts.civitai_token = token
opts.save()
with gr.Row():
gr.HTML('<h2>Fetch information</h2>Fetches preview and metadata information for all models with missing information<br>Models with existing previews and information are not updated<br>')
with gr.Row():
@@ -657,7 +668,8 @@ def create_ui():
civit_download_model_btn = gr.Button(value="Download", variant='primary')
gr.HTML('<span style="line-height: 2em">Select a model, model version and and model variant from the search results to download or enter model URL manually</span><br>')
with gr.Row():
civit_token = gr.Textbox('', label='CivitAI token', placeholder='optional access token for private or gated models')
civit_token = gr.Textbox(opts.civitai_token, label='CivitAI token', placeholder='optional access token for private or gated models')
civit_token.change(fn=civitai_update_token, inputs=[civit_token], outputs=[])
with gr.Row():
civit_name = gr.Textbox('', label='Model name', placeholder='select model from search results', visible=True)
civit_selected = gr.Textbox('', label='Model URL', placeholder='select model from search results', visible=True)