From acbb2d066ea8bc0de6f59a02258c76fa38d61de0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=AD=E3=81=8A=E3=82=93?= <240400715+neon-aiart@users.noreply.github.com> Date: Mon, 24 Nov 2025 12:29:17 +0900 Subject: [PATCH 1/2] feat: infer-web: Implement infer_loaded_voice API endpoint Implements the 'infer_loaded_voice' API endpoint to allow external clients to query the model loading status. - Adds a hidden Gradio button and JSON output component bound to the API name "infer_loaded_voice" for client access. - Corrected the usage of i18n() for Gradio labels to use English keys, ensuring internationalization compatibility. - This endpoint returns the currently loaded model ID, significantly improving reliability and user experience for external tools. --- infer-web.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/infer-web.py b/infer-web.py index 47596d539..40b845351 100644 --- a/infer-web.py +++ b/infer-web.py @@ -174,6 +174,20 @@ def change_choices(): } +def get_current_loaded_info(): + current_model = getattr(vc, "loaded_model_id", None) + + model_name = current_model if current_model else i18n("Model Not Loaded") + + data = { + "status": "success", + "model_file_name": model_name, + "info": i18n("Successfully retrieved loaded voice info."), + } + + return data + + def clean(): return {"value": "", "__type__": "update"} @@ -835,6 +849,18 @@ def change_f0_method(f0method8): fn=clean, inputs=[], outputs=[sid0], api_name="infer_clean" ) with gr.TabItem(i18n("单次推理")): + vc_status_output_json = gr.JSON( + label=i18n("Current Load Status JSON"), + visible=False, + value=get_current_loaded_info(), + ) + vc_status_button = gr.Button(i18n("Check Load Status"), visible=False) + vc_status_button.click( + fn=get_current_loaded_info, + inputs=[], + outputs=[vc_status_output_json], + api_name="infer_loaded_voice", + ) with gr.Group(): with gr.Row(): with gr.Column(): From 912390f9afa234dd5c87e3c3c119711de43d2886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=AD=E3=81=8A=E3=82=93?= <240400715+neon-aiart@users.noreply.github.com> Date: Mon, 24 Nov 2025 12:30:51 +0900 Subject: [PATCH 2/2] feat: modules: Add state variable to track loaded model ID Adds a state variable 'self.loaded_model_id' within the model loading logic in modules.py. This minimal change is necessary to persistently track which model has been loaded. It enables the new API endpoint in infer-web.py to report the current model status to the client, which is crucial for preventing premature inference errors. --- infer/modules/vc/modules.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/infer/modules/vc/modules.py b/infer/modules/vc/modules.py index 6f695cc39..7b86176c3 100644 --- a/infer/modules/vc/modules.py +++ b/infer/modules/vc/modules.py @@ -131,6 +131,8 @@ def get_vc(self, sid, *to_return_protect): index = {"value": get_index_path_from_model(sid), "__type__": "update"} logger.info("Select index: " + index["value"]) + self.loaded_model_id = sid + return ( ( {"visible": True, "maximum": n_spk, "__type__": "update"},