Skip to content

Commit

Permalink
Update Hugging Face utilities
Browse files Browse the repository at this point in the history
Hello 👋

This PR updates some attributes and methods that are now deprecated in the `huggingface_hub` library.

- `modelId` is getting deprecated huggingface/huggingface_hub#2408
- `ModelFilter` has been deprecated for some time (see huggingface/huggingface_hub#2028)

This PR will make the codebase more future-proof while being compatible with existing versions of `huggingface_hub`. Let me know if you have any questions 🤗
  • Loading branch information
Wauplin authored and carson-katri committed Aug 13, 2024
1 parent 80e7c70 commit b8f5502
Showing 1 changed file with 8 additions and 9 deletions.
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()

0 comments on commit b8f5502

Please sign in to comment.