Skip to content

Commit

Permalink
Try-except to present error when the user dont have connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Edresson committed Oct 6, 2023
1 parent 529ea3f commit 9965004
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions TTS/utils/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,24 @@ def create_dir_and_download_model(self, model_name, model_item, output_path):
raise e
self.print_model_license(model_item=model_item)

def check_if_configs_are_equal(self, model_name, model_item, output_path):
with fsspec.open(self._find_files(output_path)[1], "r", encoding="utf-8") as f:
config_local = json.load(f)
remote_url = None
for url in model_item["hf_url"]:
if "config.json" in url:
remote_url = url
break

with fsspec.open(remote_url, "r", encoding="utf-8") as f:
config_remote = json.load(f)

if not config_local == config_remote:
print(f" > {model_name} is already downloaded however it has been changed. Redownloading it...")
self.create_dir_and_download_model(model_name, model_item, output_path)
else:
print(f" > {model_name} is already downloaded.")

def download_model(self, model_name):
"""Download model files given the full model name.
Model name is in the format
Expand All @@ -364,22 +382,10 @@ def download_model(self, model_name):
# if the configs are different, redownload it
# ToDo: we need a better way to handle it
if "xtts_v1" in model_name:
with fsspec.open(self._find_files(output_path)[1], "r", encoding="utf-8") as f:
config_local = json.load(f)
remote_url = None
for url in model_item["hf_url"]:
if "config.json" in url:
remote_url = url
break

with fsspec.open(remote_url, "r", encoding="utf-8") as f:
config_remote = json.load(f)

if not config_local == config_remote:
print(f" > {model_name} is already downloaded however it has been changed. Redownloading it...")
self.create_dir_and_download_model(model_name, model_item, output_path)
else:
print(f" > {model_name} is already downloaded.")
try:
self.check_if_configs_are_equal(model_name, model_item, output_path)
except:
pass
else:
print(f" > {model_name} is already downloaded.")
else:
Expand Down

0 comments on commit 9965004

Please sign in to comment.