diffusers/sd-to-diffusers
73
1from huggingface_hub import get_hf_file_metadata, hf_hub_url, hf_hub_download, scan_cache_dir, whoami, list_models2 3 4def get_my_model_names(token):5 6 try:7 author = whoami(token=token)8 model_infos = list_models(author=author["name"], use_auth_token=token)9 return [model.modelId for model in model_infos], None10 11 except Exception as e:12 return [], e13 14def download_file(repo_id: str, filename: str, token: str):15 """Download a file from a repo on the Hugging Face Hub.16 17 Returns:18 file_path (:obj:`str`): The path to the downloaded file.19 revision (:obj:`str`): The commit hash of the file.20 """21 22 md = get_hf_file_metadata(hf_hub_url(repo_id=repo_id, filename=filename), token=token)23 revision = md.commit_hash24 25 file_path = hf_hub_download(repo_id=repo_id, filename=filename, revision=revision, token=token)26 27 return file_path, revision28 29def delete_file(revision: str):30 """Delete a file from local cache.31 32 Args:33 revision (:obj:`str`): The commit hash of the file.34 Returns:35 None36 """37 scan_cache_dir().delete_revisions(revision).execute()38 39def get_pr_url(api, repo_id, title):40 try:41 discussions = api.get_repo_discussions(repo_id=repo_id)42 except Exception:43 return None44 for discussion in discussions:45 if (46 discussion.status == "open"47 and discussion.is_pull_request48 and discussion.title == title49 ):50 return f"https://huggingface.co/{repo_id}/discussions/{discussion.num}"