Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Hugging Face utilities #813

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions generator_process/actions/huggingface_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,23 @@ def hf_list_models(
query: str,
token: str,
) -> list[Model]:
from huggingface_hub import HfApi, ModelFilter
from huggingface_hub import HfApi

if hasattr(self, "huggingface_hub_api"):
api: HfApi = self.huggingface_hub_api
else:
api = HfApi()
setattr(self, "huggingface_hub_api", api)

filter = ModelFilter(tags="diffusers")

models = api.list_models(
filter=filter,
tags="diffusers",
search=query,
use_auth_token=token
token=token,
)
return [
Model(m.modelId, m.author or "", m.tags, m.likes if hasattr(m, "likes") else 0, getattr(m, "downloads", -1), ModelType.UNKNOWN)
Model(m.id, m.author or "", m.tags, m.likes if hasattr(m, "likes") else 0, getattr(m, "downloads", -1), ModelType.UNKNOWN)
for m in models
if m.modelId is not None and m.tags is not None and 'diffusers' in (m.tags or {})
if m.id is not None and m.tags is not None and 'diffusers' in (m.tags or {})
]

def hf_list_installed_models(self) -> list[Model]:
Expand Down Expand Up @@ -177,7 +176,7 @@ def hf_snapshot_download(
_, variant_files = variant_compatible_siblings(files, variant=variant)
StableDiffusionPipeline.download(
model,
use_auth_token=token,
token=token,
variant=variant if len(variant_files) > 0 else None,
resume_download=resume_download,
)
Expand All @@ -204,4 +203,4 @@ def hf_snapshot_download(
else:
raise ValueError(f"{model} doesn't appear to be a pipeline or model")

future.set_done()
future.set_done()