From d51c8bf6392ea9e3468368af7ae20b6ca1b5d694 Mon Sep 17 00:00:00 2001 From: litagin02 Date: Wed, 7 Feb 2024 15:33:17 +0900 Subject: [PATCH] Fix: conflict of current_model in model_holder for multiple requests --- app.py | 6 +++++- common/tts_model.py | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 284098f..5665cf2 100644 --- a/app.py +++ b/app.py @@ -36,6 +36,8 @@ languages = [l.value for l in Languages] def tts_fn( + model_name, + model_path, text, language, reference_audio_path, @@ -54,7 +56,7 @@ def tts_fn( use_tone, speaker, ): - assert model_holder.current_model is not None + model_holder.load_model_gr(model_name, model_path) wrong_tone_message = "" kata_tone: Optional[list[tuple[str, int]]] = None @@ -418,6 +420,8 @@ if __name__ == "__main__": tts_button.click( tts_fn, inputs=[ + model_name, + model_path, text_input, language, ref_audio_path, diff --git a/common/tts_model.py b/common/tts_model.py index 7f44256..c148598 100644 --- a/common/tts_model.py +++ b/common/tts_model.py @@ -209,6 +209,18 @@ class ModelHolder: raise ValueError(f"Model `{model_name}` is not found") if model_path not in self.model_files_dict[model_name]: raise ValueError(f"Model file `{model_path}` is not found") + if ( + self.current_model is not None + and self.current_model.model_path == model_path + ): + # Already loaded + speakers = list(self.current_model.spk2id.keys()) + styles = list(self.current_model.style2id.keys()) + return ( + gr.Dropdown(choices=styles, value=styles[0]), + gr.Button(interactive=True, value="音声合成"), + gr.Dropdown(choices=speakers, value=speakers[0]), + ) self.current_model = Model( model_path=model_path, config_path=os.path.join(self.root_dir, model_name, "config.json"),