Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -41,7 +41,7 @@ data = {
|
|
41 |
model_configurations = {}
|
42 |
# Define global variables
|
43 |
onnx_models = [] # A list to store model names
|
44 |
-
|
45 |
speaker_id_map = {
|
46 |
"speaker1": "Speaker 1 Name",
|
47 |
"speaker2": "Speaker 2 Name",
|
@@ -139,7 +139,7 @@ async def get_speaker_id_map(selected_model: str):
|
|
139 |
|
140 |
@app.on_event("startup")
|
141 |
async def load_model_data():
|
142 |
-
global onnx_models, model_configurations # Make
|
143 |
# Load data for all models in the directory upon startup
|
144 |
sys.path.append('./content/piper/src/python')
|
145 |
models_path = "./content/piper/src/python"
|
@@ -156,13 +156,13 @@ async def load_model_data():
|
|
156 |
onnx_models = model_names # Populate onnx_models here
|
157 |
for config_name in config_names:
|
158 |
# Load the configuration data for each model (including speaker_id_map)
|
159 |
-
config = load_model_configuration(config_name)
|
160 |
-
model_configurations[config_name] = config
|
161 |
|
162 |
def load_model_configuration(config_name):
|
163 |
-
# Assuming config_name is the path to the
|
164 |
-
config_file_path = config_name
|
165 |
-
|
166 |
try:
|
167 |
with open(config_file_path, 'r') as config_file:
|
168 |
config_data = json.load(config_file)
|
@@ -171,6 +171,7 @@ def load_model_configuration(config_name):
|
|
171 |
# Handle the case where the configuration file does not exist
|
172 |
return None
|
173 |
|
|
|
174 |
|
175 |
@app.post("/", response_class=HTMLResponse)
|
176 |
async def main(
|
|
|
41 |
model_configurations = {}
|
42 |
# Define global variables
|
43 |
onnx_models = [] # A list to store model names
|
44 |
+
onnx_configs = []
|
45 |
speaker_id_map = {
|
46 |
"speaker1": "Speaker 1 Name",
|
47 |
"speaker2": "Speaker 2 Name",
|
|
|
139 |
|
140 |
@app.on_event("startup")
|
141 |
async def load_model_data():
|
142 |
+
global onnx_models, model_configurations # Make onnx_models and model_configurations available globally
|
143 |
# Load data for all models in the directory upon startup
|
144 |
sys.path.append('./content/piper/src/python')
|
145 |
models_path = "./content/piper/src/python"
|
|
|
156 |
onnx_models = model_names # Populate onnx_models here
|
157 |
for config_name in config_names:
|
158 |
# Load the configuration data for each model (including speaker_id_map)
|
159 |
+
config = load_model_configuration(config_name)
|
160 |
+
model_configurations[config_name] = config
|
161 |
|
162 |
def load_model_configuration(config_name):
|
163 |
+
# Assuming config_name is the path to the JSON configuration file, e.g., 'model.json'
|
164 |
+
config_file_path = os.path.join(models_path, config_name)
|
165 |
+
|
166 |
try:
|
167 |
with open(config_file_path, 'r') as config_file:
|
168 |
config_data = json.load(config_file)
|
|
|
171 |
# Handle the case where the configuration file does not exist
|
172 |
return None
|
173 |
|
174 |
+
|
175 |
|
176 |
@app.post("/", response_class=HTMLResponse)
|
177 |
async def main(
|