File size: 1,162 Bytes
7a47baa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()