Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,31 +6,11 @@ import os
|
|
6 |
import random
|
7 |
import string
|
8 |
import re
|
9 |
-
import logging
|
10 |
|
11 |
app = Flask(__name__)
|
12 |
|
13 |
-
# Define
|
14 |
-
|
15 |
-
"Español México | Kamora Neuronal": {
|
16 |
-
"model_path": "es_ES-kamora-7539-high.onnx",
|
17 |
-
"replacements": [('\n', '. ')]
|
18 |
-
},
|
19 |
-
"Español México | Claude": {
|
20 |
-
"model_path": "es_MX-claude-14947-epoch-high.onnx",
|
21 |
-
"replacements": [('(', ','), (')', ','), ('?', ','), ('¿', ','), (':', ','), ('\n', ' ')]
|
22 |
-
}
|
23 |
-
}
|
24 |
-
|
25 |
-
# Comprueba si los modelos definidos existen en la carpeta de modelos
|
26 |
-
model_folder = '/home/app/'
|
27 |
-
existing_models = [model_name for model_name in model_names.keys() if os.path.isfile(os.path.join(model_folder, model_names[model_name]["model_path"]))]
|
28 |
-
|
29 |
-
def multiple_replace(text, replacements):
|
30 |
-
# Iterar sobre cada par de remplazo
|
31 |
-
for old, new in replacements:
|
32 |
-
text = text.replace(old, new)
|
33 |
-
return text
|
34 |
|
35 |
def filter_text(text, model_name):
|
36 |
if model_name in model_names:
|
@@ -44,20 +24,18 @@ def filter_text(text, model_name):
|
|
44 |
logging.error(f"No se encontró el modelo '{model_name}'.")
|
45 |
return None
|
46 |
|
47 |
-
|
48 |
-
#
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
return None
|
53 |
-
|
54 |
random_name = ''.join(random.choices(string.ascii_letters + string.digits, k=8)) + '.wav'
|
55 |
-
output_file = os.path.join(
|
56 |
app.logger.info("Audio file created at: %s", output_file)
|
57 |
-
piper_exe = os.path.join(
|
58 |
|
59 |
if os.path.isfile(piper_exe):
|
60 |
-
comando = f'echo {
|
61 |
subprocess.run(comando, shell=True)
|
62 |
return output_file
|
63 |
else:
|
@@ -66,9 +44,10 @@ def convert_text_to_speech(text, model_name):
|
|
66 |
|
67 |
@app.route('/')
|
68 |
def index():
|
|
|
69 |
model_options = [file for file in os.listdir(model_folder) if file.endswith('.onnx')]
|
70 |
# Log the contents of the current folder
|
71 |
-
app.logger.info("Contents of current folder: %s", os.listdir(
|
72 |
return render_template('index.html', model_options=model_options)
|
73 |
|
74 |
@app.route('/convert', methods=['POST'])
|
@@ -96,4 +75,4 @@ def convert_text():
|
|
96 |
return response
|
97 |
|
98 |
if __name__ == '__main__':
|
99 |
-
app.run(host='0.0.0.0', port=7860, debug=False)
|
|
|
6 |
import random
|
7 |
import string
|
8 |
import re
|
|
|
9 |
|
10 |
app = Flask(__name__)
|
11 |
|
12 |
+
# Define the folder where files are saved
|
13 |
+
file_folder = '/home/app/'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
def filter_text(text, model_name):
|
16 |
if model_name in model_names:
|
|
|
24 |
logging.error(f"No se encontró el modelo '{model_name}'.")
|
25 |
return None
|
26 |
|
27 |
+
def convert_text_to_speech(parrafo, model):
|
28 |
+
# Limit text to 500 characters
|
29 |
+
parrafo = parrafo[:100000]
|
30 |
+
|
31 |
+
parrafo_filtrado = filter_text(parrafo)
|
|
|
|
|
32 |
random_name = ''.join(random.choices(string.ascii_letters + string.digits, k=8)) + '.wav'
|
33 |
+
output_file = os.path.join(file_folder, random_name)
|
34 |
app.logger.info("Audio file created at: %s", output_file)
|
35 |
+
piper_exe = os.path.join(file_folder, 'piper') # Adjusted the path for piper
|
36 |
|
37 |
if os.path.isfile(piper_exe):
|
38 |
+
comando = f'echo {parrafo_filtrado} | "{piper_exe}" -m {model} -f {output_file}'
|
39 |
subprocess.run(comando, shell=True)
|
40 |
return output_file
|
41 |
else:
|
|
|
44 |
|
45 |
@app.route('/')
|
46 |
def index():
|
47 |
+
model_folder = file_folder # Adjusted the model folder to file_folder
|
48 |
model_options = [file for file in os.listdir(model_folder) if file.endswith('.onnx')]
|
49 |
# Log the contents of the current folder
|
50 |
+
app.logger.info("Contents of current folder: %s", os.listdir(file_folder))
|
51 |
return render_template('index.html', model_options=model_options)
|
52 |
|
53 |
@app.route('/convert', methods=['POST'])
|
|
|
75 |
return response
|
76 |
|
77 |
if __name__ == '__main__':
|
78 |
+
app.run(host='0.0.0.0', port=7860, debug=False)
|