"vscode:/vscode.git/clone" did not exist on "62f4d6636cce72fc7db792f894d619da7bdb2fec"
export-hf-model.py 1.08 KB
Newer Older
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
import os
import shutil

MODEL_NAME = "distil-whisper/large-v2"
HF_CACHE_DIR = "/root/.cache/huggingface/hub/"
hash_code = None
# models--distil-whisper--large-v2/snapshots/66bb165856c86b9eae9dba7830c0cd7d859f4ef4/"
for cache_model_name in os.listdir(HF_CACHE_DIR):
    flag = False
    for model_name_str_split in MODEL_NAME.split("/"):
        if model_name_str_split in cache_model_name:
            flag = True
        else:
            flag = False
            break
    if flag:
        if hash_code is None:
            full_path = os.path.join(HF_CACHE_DIR, cache_model_name, "snapshots",
                                     os.listdir(os.path.join(HF_CACHE_DIR, cache_model_name, "snapshots"))[0])
        else:
            full_path = os.path.join(HF_CACHE_DIR, cache_model_name, "snapshots", hash_code)
        os.makedirs(MODEL_NAME, exist_ok=True)
        for filename in os.listdir(full_path):
            shutil.copy(os.path.join(full_path, filename), os.path.join(MODEL_NAME, filename))
            print("copy: ", os.path.join(full_path, filename), " to ", os.path.join(MODEL_NAME, filename))