From ecc788687e5dcc30f80db476fb8c5c8f72819f92 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 26 Jun 2024 03:07:30 +0000 Subject: [PATCH] chore(format): run black on main --- ChatTTS/core.py | 13 ++++++++----- ChatTTS/model/gpt.py | 16 ++++++++++++---- ChatTTS/model/processors.py | 5 ++++- examples/web/ex.py | 2 +- examples/web/funcs.py | 2 +- 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/ChatTTS/core.py b/ChatTTS/core.py index b74310fe9..567ebf52a 100644 --- a/ChatTTS/core.py +++ b/ChatTTS/core.py @@ -70,10 +70,15 @@ def download_models( ) -> Optional[str]: if source == "local": download_path = os.getcwd() - if not check_all_assets(Path(download_path), self.sha256_map, update=True) or force_redownload: + if ( + not check_all_assets(Path(download_path), self.sha256_map, update=True) + or force_redownload + ): with tempfile.TemporaryDirectory() as tmp: download_all_assets(tmpdir=tmp) - if not check_all_assets(Path(download_path), self.sha256_map, update=False): + if not check_all_assets( + Path(download_path), self.sha256_map, update=False + ): self.logger.error( "download to local path %s failed.", download_path ) @@ -107,9 +112,7 @@ def download_models( elif source == "custom": self.logger.log(logging.INFO, f"try to load from local: {custom_path}") if not check_all_assets(Path(custom_path), self.sha256_map, update=False): - self.logger.error( - "check models in custom path %s failed.", custom_path - ) + self.logger.error("check models in custom path %s failed.", custom_path) return None download_path = custom_path diff --git a/ChatTTS/model/gpt.py b/ChatTTS/model/gpt.py index ee9467867..ab049c9ca 100644 --- a/ChatTTS/model/gpt.py +++ b/ChatTTS/model/gpt.py @@ -226,7 +226,9 @@ def _prepare_generation_inputs( # 2 - If the past_length is smaller than input_ids', then input_ids holds all input tokens. We can discard # input_ids based on the past_length. elif past_length < input_ids.shape[1]: - input_ids = input_ids.narrow(1, past_length, input_ids.size(1)-past_length) + input_ids = input_ids.narrow( + 1, past_length, input_ids.size(1) - past_length + ) # 3 - Otherwise (past_length >= input_ids.shape[1]), let's assume input_ids only has unprocessed tokens. # If we are about to go beyond the maximum cache length, we need to crop the input attention mask. @@ -235,14 +237,18 @@ def _prepare_generation_inputs( and attention_mask is not None and cache_length + input_ids.shape[1] > max_cache_length ): - attention_mask = attention_mask.narrow(1, -max_cache_length, max_cache_length) + attention_mask = attention_mask.narrow( + 1, -max_cache_length, max_cache_length + ) if attention_mask is not None and position_ids is None: # create position_ids on the fly for batch generation position_ids = attention_mask.long().cumsum(-1) - 1 position_ids.masked_fill_(attention_mask == 0, 1) if past_key_values: - position_ids = position_ids.narrow(1, -input_ids.shape[1], input_ids.shape[1]) + position_ids = position_ids.narrow( + 1, -input_ids.shape[1], input_ids.shape[1] + ) input_length = ( position_ids.shape[-1] if position_ids is not None else input_ids.shape[-1] @@ -360,7 +366,9 @@ def generate( device=inputs_ids.device, ) if attention_mask is not None: - attention_mask_cache.narrow(1, 0, attention_mask.shape[1]).copy_(attention_mask) + attention_mask_cache.narrow(1, 0, attention_mask.shape[1]).copy_( + attention_mask + ) with tqdm( total=max_new_token, diff --git a/ChatTTS/model/processors.py b/ChatTTS/model/processors.py index 41c4aff92..f774dd27f 100644 --- a/ChatTTS/model/processors.py +++ b/ChatTTS/model/processors.py @@ -22,7 +22,9 @@ def __call__( input_ids = input_ids.narrow(1, -self.past_window, self.past_window) freq = F.one_hot(input_ids, scores.size(1)).sum(1) if freq.size(0) > self.max_input_ids: - freq.narrow(0, self.max_input_ids, freq.size(0)-self.max_input_ids).zero_() + freq.narrow( + 0, self.max_input_ids, freq.size(0) - self.max_input_ids + ).zero_() alpha = torch.pow(self.penalty, freq) scores = scores.contiguous() inp = scores.multiply(alpha) @@ -32,6 +34,7 @@ def __call__( del inp, oth, scores, con, alpha return out + def gen_logits( num_code: int, top_P=0.7, diff --git a/examples/web/ex.py b/examples/web/ex.py index 3dbd3123b..f39dac78b 100644 --- a/examples/web/ex.py +++ b/examples/web/ex.py @@ -1,4 +1,4 @@ -ex=[ +ex = [ [ "四川美食确实以辣闻名,但也有不辣的选择。比如甜水面、赖汤圆、蛋烘糕、叶儿粑等,这些小吃口味温和,甜而不腻,也很受欢迎。", 0.3, diff --git a/examples/web/funcs.py b/examples/web/funcs.py index dcff4f5fe..167c89a5f 100644 --- a/examples/web/funcs.py +++ b/examples/web/funcs.py @@ -108,7 +108,7 @@ def refine_text( has_interrupted = False if not refine_text_flag: - sleep(1) # to skip fast answer of loading mark + sleep(1) # to skip fast answer of loading mark return text, *set_generate_buttons( generate_button, interrupt_button, is_reset=True )