Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -105,12 +105,15 @@ class Translator:
|
|
105 |
lan = Translator()
|
106 |
def detect_onnx_models(path):
|
107 |
onnx_models = glob.glob(path + '/*.onnx')
|
|
|
108 |
if len(onnx_models) > 1:
|
109 |
-
return onnx_models
|
110 |
elif len(onnx_models) == 1:
|
111 |
-
return onnx_models[0]
|
112 |
else:
|
113 |
return None
|
|
|
|
|
114 |
renamed_audio_file = None
|
115 |
|
116 |
model_configurations = {}
|
@@ -130,10 +133,7 @@ async def load_model_data():
|
|
130 |
|
131 |
# Collect data for all models in the directory and populate model_configurations
|
132 |
onnx_models = detect_onnx_models(models_path)
|
133 |
-
|
134 |
-
# Load the configuration data for each model (including speaker_id_map)
|
135 |
-
config = load_model_configuration(model_name)
|
136 |
-
model_configurations[model_name] = config
|
137 |
|
138 |
#@app.post("/synthesize")
|
139 |
#@app.post("/", response_class=FileResponse)
|
@@ -171,7 +171,7 @@ async def main(
|
|
171 |
# layout={'visibility': 'hidden'}
|
172 |
# )
|
173 |
# Handle loading the selected model and speaker ID here
|
174 |
-
if selected_model in
|
175 |
config = model_configurations[selected_model]
|
176 |
onnx_model = config["onnx_model"] # Replace with the actual key for your ONNX model file
|
177 |
model, config = load_onnx(onnx_model, sess_options, providers)
|
@@ -184,7 +184,7 @@ async def main(
|
|
184 |
document.getElementById("synthesize_button").disabled = true;
|
185 |
</script>
|
186 |
"""
|
187 |
-
onnx_model =
|
188 |
model, config = load_onnx(onnx_model, sess_options, providers)
|
189 |
|
190 |
|
@@ -302,7 +302,12 @@ async def main(
|
|
302 |
|
303 |
|
304 |
# Save the audio as a temporary WAV file
|
305 |
-
return templates.TemplateResponse("interface.html", {"request": request, "file_url": file_url, "text_input": text_input, "data": data, "
|
|
|
|
|
|
|
|
|
|
|
306 |
|
307 |
# Serve the audio file with the correct media type
|
308 |
# return FileResponse(renamed_audio_file)
|
|
|
105 |
lan = Translator()
|
106 |
def detect_onnx_models(path):
|
107 |
onnx_models = glob.glob(path + '/*.onnx')
|
108 |
+
onnx_configs = glob.glob(path + '/*.json')
|
109 |
if len(onnx_models) > 1:
|
110 |
+
return onnx_models, onnx_configs
|
111 |
elif len(onnx_models) == 1:
|
112 |
+
return onnx_models[0], onnx_configs[0]
|
113 |
else:
|
114 |
return None
|
115 |
+
|
116 |
+
|
117 |
renamed_audio_file = None
|
118 |
|
119 |
model_configurations = {}
|
|
|
133 |
|
134 |
# Collect data for all models in the directory and populate model_configurations
|
135 |
onnx_models = detect_onnx_models(models_path)
|
136 |
+
|
|
|
|
|
|
|
137 |
|
138 |
#@app.post("/synthesize")
|
139 |
#@app.post("/", response_class=FileResponse)
|
|
|
171 |
# layout={'visibility': 'hidden'}
|
172 |
# )
|
173 |
# Handle loading the selected model and speaker ID here
|
174 |
+
if selected_model in onnx_models:
|
175 |
config = model_configurations[selected_model]
|
176 |
onnx_model = config["onnx_model"] # Replace with the actual key for your ONNX model file
|
177 |
model, config = load_onnx(onnx_model, sess_options, providers)
|
|
|
184 |
document.getElementById("synthesize_button").disabled = true;
|
185 |
</script>
|
186 |
"""
|
187 |
+
onnx_model = selected_model
|
188 |
model, config = load_onnx(onnx_model, sess_options, providers)
|
189 |
|
190 |
|
|
|
302 |
|
303 |
|
304 |
# Save the audio as a temporary WAV file
|
305 |
+
return templates.TemplateResponse("interface.html", {"request": request, "file_url": file_url, "text_input": text_input, "data": data, "model_names": model_configurations.keys(), # Pass the list of available model names
|
306 |
+
"selected_model": selected_model, # Pass the selected model
|
307 |
+
"speaker_id_map": speaker_id_map, # Pass the speaker ID map for the selected model
|
308 |
+
"selected_speaker_id": selected_speaker_id, # Pass the selected speaker ID
|
309 |
+
# "model": model, # Pass the loaded model (if any)
|
310 |
+
"voices": voices, "dynamic_content": response_html})
|
311 |
|
312 |
# Serve the audio file with the correct media type
|
313 |
# return FileResponse(renamed_audio_file)
|