From 99650044a432c619f4ae63258d62bea053a58fe3 Mon Sep 17 00:00:00 2001 From: Edresson Casanova Date: Fri, 6 Oct 2023 17:37:05 -0300 Subject: [PATCH] Try-except to present error when the user dont have connection --- TTS/utils/manage.py | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/TTS/utils/manage.py b/TTS/utils/manage.py index fedab1d3..0420fc0d 100644 --- a/TTS/utils/manage.py +++ b/TTS/utils/manage.py @@ -343,6 +343,24 @@ class ModelManager(object): 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 @@ -364,22 +382,10 @@ class ModelManager(object): # 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: