From 4a6103fec9503024ed7d0bada7286e70c45a774a Mon Sep 17 00:00:00 2001 From: Edresson Casanova Date: Fri, 6 Oct 2023 17:16:30 -0300 Subject: [PATCH 1/7] Redownload XTTS with the local and remote config do not match --- TTS/utils/manage.py | 68 +++++++++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 21 deletions(-) diff --git a/TTS/utils/manage.py b/TTS/utils/manage.py index b5c698f3..dbd9d7c0 100644 --- a/TTS/utils/manage.py +++ b/TTS/utils/manage.py @@ -6,6 +6,7 @@ from pathlib import Path from shutil import copyfile, rmtree from typing import Dict, List, Tuple +import fsspec import requests from tqdm import tqdm @@ -320,6 +321,31 @@ class ModelManager(object): return False return True + def check_if_files_size(self, model_name): + pass + + def create_dir_and_download_model(self, model_name, model_item, output_path): + os.makedirs(output_path, exist_ok=True) + # handle TOS + if not self.tos_agreed(model_item, output_path): + if not self.ask_tos(output_path): + os.rmdir(output_path) + raise Exception(" [!] You must agree to the terms of service to use this model.") + print(f" > Downloading model to {output_path}") + try: + if "fairseq" in model_name: + self.download_fairseq_model(model_name, output_path) + elif "github_rls_url" in model_item: + self._download_github_model(model_item, output_path) + elif "hf_url" in model_item: + self._download_hf_model(model_item, output_path) + + except requests.RequestException as e: + print(f" > Failed to download the model file to {output_path}") + rmtree(output_path) + raise e + self.print_model_license(model_item=model_item) + def download_model(self, model_name): """Download model files given the full model name. Model name is in the format @@ -338,28 +364,28 @@ class ModelManager(object): # set the model specific output path output_path = os.path.join(self.output_prefix, model_full_name) if os.path.exists(output_path): - print(f" > {model_name} is already downloaded.") - else: - os.makedirs(output_path, exist_ok=True) - # handle TOS - if not self.tos_agreed(model_item, output_path): - if not self.ask_tos(output_path): - os.rmdir(output_path) - raise Exception(" [!] You must agree to the terms of service to use this model.") - print(f" > Downloading model to {output_path}") - try: - if "fairseq" in model_name: - self.download_fairseq_model(model_name, output_path) - elif "github_rls_url" in model_item: - self._download_github_model(model_item, output_path) - elif "hf_url" in model_item: - self._download_hf_model(model_item, output_path) + # 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.") + else: + self.create_dir_and_download_model(model_name, model_item, output_path) - except requests.RequestException as e: - print(f" > Failed to download the model file to {output_path}") - rmtree(output_path) - raise e - self.print_model_license(model_item=model_item) # find downloaded files output_model_path = output_path output_config_path = None From ee1ef1c51e183c9236d4b598afda0e8c828a8ec9 Mon Sep 17 00:00:00 2001 From: Edresson Casanova Date: Fri, 6 Oct 2023 17:21:22 -0300 Subject: [PATCH 2/7] Remove unused method --- TTS/utils/manage.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/TTS/utils/manage.py b/TTS/utils/manage.py index dbd9d7c0..288cc118 100644 --- a/TTS/utils/manage.py +++ b/TTS/utils/manage.py @@ -321,9 +321,6 @@ class ModelManager(object): return False return True - def check_if_files_size(self, model_name): - pass - def create_dir_and_download_model(self, model_name, model_item, output_path): os.makedirs(output_path, exist_ok=True) # handle TOS From 529ea3f67f584cdc77c9d65a45da1e12043f970b Mon Sep 17 00:00:00 2001 From: Edresson Casanova Date: Fri, 6 Oct 2023 17:26:40 -0300 Subject: [PATCH 3/7] Print a message when it is already donwloaded --- TTS/utils/manage.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TTS/utils/manage.py b/TTS/utils/manage.py index 288cc118..fedab1d3 100644 --- a/TTS/utils/manage.py +++ b/TTS/utils/manage.py @@ -378,6 +378,8 @@ class ModelManager(object): 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.") else: print(f" > {model_name} is already downloaded.") else: From 99650044a432c619f4ae63258d62bea053a58fe3 Mon Sep 17 00:00:00 2001 From: Edresson Casanova Date: Fri, 6 Oct 2023 17:37:05 -0300 Subject: [PATCH 4/7] 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: From 2852404bdffbb8bc970444a855273647ea2e78c4 Mon Sep 17 00:00:00 2001 From: Edresson Casanova Date: Fri, 6 Oct 2023 17:42:46 -0300 Subject: [PATCH 5/7] Fix style --- TTS/utils/manage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TTS/utils/manage.py b/TTS/utils/manage.py index 0420fc0d..955eeb9b 100644 --- a/TTS/utils/manage.py +++ b/TTS/utils/manage.py @@ -385,7 +385,7 @@ class ModelManager(object): try: self.check_if_configs_are_equal(model_name, model_item, output_path) except: - pass + pass else: print(f" > {model_name} is already downloaded.") else: From 3bb51b1276b1f203a65df6e9fcedcfa2f0b23dd9 Mon Sep 17 00:00:00 2001 From: ggoknar Date: Sat, 7 Oct 2023 01:13:02 +0300 Subject: [PATCH 6/7] 0.17.8 --- TTS/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TTS/VERSION b/TTS/VERSION index 79394953..7df1fd55 100644 --- a/TTS/VERSION +++ b/TTS/VERSION @@ -1 +1 @@ -0.17.7 +v0.17.8 From 99635193f508092c746febb087dc6634fa5f59d8 Mon Sep 17 00:00:00 2001 From: ggoknar Date: Sat, 7 Oct 2023 01:14:05 +0300 Subject: [PATCH 7/7] v0.17.8 --- TTS/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TTS/VERSION b/TTS/VERSION index 7df1fd55..8bb22944 100644 --- a/TTS/VERSION +++ b/TTS/VERSION @@ -1 +1 @@ -v0.17.8 +0.17.8