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))
