support manually downloaded hf models

Signed-off-by: Vladimir Mandic <mandic00@live.com>
This commit is contained in:
Vladimir Mandic
2024-10-04 09:15:19 -04:00
parent 462e9f5721
commit b787d5fd6f
3 changed files with 8 additions and 2 deletions
+1
View File
@@ -134,6 +134,7 @@ And other goodies like multiple *XYZ grid* improvements, additional *Flux Contro
- **python 3.12** improved compatibility, automatically handle `setuptools`
- **control** persist/reapply units current state on server restart
- **video** add option `gradio_skip_video` to avoid gradio issues with displaying generated videos
- add support for manually downloaded diffusers models from huggingface
- **ui**
- hide token counter until tokens are known
- minor ui optimizations
+5 -2
View File
@@ -258,7 +258,6 @@ def download_diffusers_model(hub_id: str, cache_dir: str = None, download_config
def load_diffusers_models(clear=True):
# excluded_models = ['PhotoMaker', 'inswapper_128', 'IP-Adapter']
excluded_models = []
t0 = time.time()
place = shared.opts.diffusers_dir
@@ -279,11 +278,15 @@ def load_diffusers_models(clear=True):
name = name.replace("--", "/")
folder = os.path.join(place, folder)
friendly = os.path.join(place, name)
if os.path.exists(os.path.join(folder, 'model_index.json')): # direct download of diffusers model
repo = { 'name': name, 'filename': name, 'friendly': friendly, 'folder': folder, 'path': folder, 'hash': '', 'mtime': os.path.getmtime(folder), 'model_info': os.path.join(folder, 'model_info.json'), 'model_index': os.path.join(folder, 'model_index.json') }
diffuser_repos.append(repo)
continue
snapshots = os.listdir(os.path.join(folder, "snapshots"))
if len(snapshots) == 0:
shared.log.warning(f'Diffusers folder has no snapshots: location="{place}" folder="{folder}" name="{name}"')
continue
for snapshot in snapshots:
for snapshot in snapshots: # download using from_pretrained which uses huggingface_hub or huggingface_hub directly and creates snapshot-like structure
commit = os.path.join(folder, 'snapshots', snapshot)
mtime = os.path.getmtime(commit)
info = os.path.join(commit, "model_info.json")
+2
View File
@@ -362,6 +362,8 @@ class ExtraNetworksPage:
item['local_preview'] = f'{base}.{shared.opts.samples_format}'
if shared.opts.diffusers_dir in base:
match = re.search(r"models--([^/^\\]+)[/\\]", base)
if match is None:
match = re.search(r"models--(.*)", base)
base = os.path.join(reference_path, match[1])
model_path = os.path.join(shared.opts.diffusers_dir, match[0])
item['local_preview'] = f'{os.path.join(model_path, match[1])}.{shared.opts.samples_format}'