make model switch work with toast

This commit is contained in:
Sanster
2022-04-17 23:31:12 +08:00
parent 205286a414
commit f7e1e073dc
18 changed files with 447 additions and 28 deletions

View File

@@ -9,7 +9,7 @@ import torch
from torch.hub import download_url_to_file, get_dir
def download_model(url):
def get_cache_path_by_url(url):
parts = urlparse(url)
hub_dir = get_dir()
model_dir = os.path.join(hub_dir, "checkpoints")
@@ -17,6 +17,11 @@ def download_model(url):
os.makedirs(os.path.join(model_dir, "hub", "checkpoints"))
filename = os.path.basename(parts.path)
cached_file = os.path.join(model_dir, filename)
return cached_file
def download_model(url):
cached_file = get_cache_path_by_url(url)
if not os.path.exists(cached_file):
sys.stderr.write('Downloading: "{}" to {}\n'.format(url, cached_file))
hash_prefix = None