From 640b8279bfdb585d70c7110f214b5e77e7656722 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Sat, 27 Jan 2024 09:28:53 -0500 Subject: [PATCH] add hf token to settings --- modules/modelloader.py | 35 ++++++++++++++++++++--------------- modules/shared.py | 1 + wiki | 2 +- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/modules/modelloader.py b/modules/modelloader.py index d3c0e11ca..00c29ac85 100644 --- a/modules/modelloader.py +++ b/modules/modelloader.py @@ -12,6 +12,7 @@ from modules.paths import script_path, models_path diffuser_repos = [] +debug = shared.log.trace if os.environ.get('SD_DOWNLOAD_DEBUG', None) is not None else lambda *args, **kwargs: None def download_civit_meta(model_path: str, model_id): @@ -166,31 +167,35 @@ def download_diffusers_model(hub_id: str, cache_dir: str = None, download_config download_config["mirror"] = mirror if custom_pipeline is not None and len(custom_pipeline) > 0: download_config["custom_pipeline"] = custom_pipeline - shared.log.debug(f"Diffusers downloading: {hub_id} args={download_config}") + shared.log.debug(f'Diffusers downloading: id="{hub_id}" args={download_config}') + token = token or shared.opts.huggingface_token if token is not None and len(token) > 2: shared.log.debug(f"Diffusers authentication: {token}") hf.login(token) pipeline_dir = None - ok = True + ok = False err = None - try: - pipeline_dir = DiffusionPipeline.download(hub_id, **download_config) - except Exception as e: - err = e - ok = False - # shared.log.warning(f"Diffusers download error: {hub_id} {e}") + if not ok: + try: + pipeline_dir = DiffusionPipeline.download(hub_id, **download_config) + ok = True + except Exception as e: + err = e + ok = False + debug(f"Diffusers download error: {hub_id} {e}") if not ok and 'Repository Not Found' not in str(err): try: - download_config.pop('load_connected_pipeline') - download_config.pop('variant') + download_config.pop('load_connected_pipeline', None) + download_config.pop('variant', None) pipeline_dir = hf.snapshot_download(hub_id, **download_config) - except Exception: - # shared.log.warning(f"Diffusers download error: {hub_id} {e}") - pass - + except Exception as e: + debug(f"Diffusers download error: {hub_id} {e}") + if 'gated' in str(e): + shared.log.error(f'Diffusers download error: id="{hub_id}" model access requires login') + return None if pipeline_dir is None: - shared.log.error(f"Diffusers download error: {hub_id} {err}") + shared.log.error(f'Diffusers download error: id="{hub_id}" {err}') return None try: model_info_dict = hf.model_info(hub_id).cardData if pipeline_dir is not None else None diff --git a/modules/shared.py b/modules/shared.py index ed88819bf..babe8cc28 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -432,6 +432,7 @@ options_templates.update(options_section(('diffusers', "Diffusers Settings"), { "diffusers_force_zeros": OptionInfo(False, "Force zeros for prompts when empty", gr.Checkbox, {"visible": False}), "diffusers_aesthetics_score": OptionInfo(False, "Require aesthetics score"), "diffusers_pooled": OptionInfo("default", "Diffusers SDXL pooled embeds", gr.Radio, {"choices": ['default', 'weighted']}), + "huggingface_token": OptionInfo('', 'HuggingFace token'), })) options_templates.update(options_section(('system-paths', "System Paths"), { diff --git a/wiki b/wiki index d54a64b47..0bf8476d8 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit d54a64b47bb3f2abfebea9779ce694e6cf0c219d +Subproject commit 0bf8476d8188df5922efd86d108729aeb34277f8