File size: 1,583 Bytes
e0097f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from huggingface_hub import get_hf_file_metadata, hf_hub_url, hf_hub_download, scan_cache_dir, whoami, list_models


def get_my_model_names(token):
    
    try:
        author = whoami(token=token)
        model_infos = list_models(author=author["name"], use_auth_token=token)
        return [model.modelId for model in model_infos], None
        
    except Exception as e:
        return [], e

def download_file(repo_id: str, filename: str, token: str):
    """Download a file from a repo on the Hugging Face Hub.

    Returns:
        file_path (:obj:`str`): The path to the downloaded file.
        revision (:obj:`str`): The commit hash of the file.
        """

    md = get_hf_file_metadata(hf_hub_url(repo_id=repo_id, filename=filename), token=token)
    revision = md.commit_hash

    file_path = hf_hub_download(repo_id=repo_id, filename=filename, revision=revision, token=token)

    return file_path, revision

def delete_file(revision: str):
    """Delete a file from local cache.

    Args:
        revision (:obj:`str`): The commit hash of the file.
    Returns:
        None
        """
    scan_cache_dir().delete_revisions(revision).execute()

def get_pr_url(api, repo_id, title):
    try:
        discussions = api.get_repo_discussions(repo_id=repo_id)
    except Exception:
        return None
    for discussion in discussions:
        if (
            discussion.status == "open"
            and discussion.is_pull_request
            and discussion.title == title
        ):
            return f"https://huggingface.co/{repo_id}/discussions/{discussion.num}"