Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -13,7 +13,7 @@ app = Flask(__name__)
|
|
13 |
# Define los nombres asignados a modelos específicos, en caso de no existir no se muestran
|
14 |
model_names = {
|
15 |
"Español México | Kamora Neuronal": {
|
16 |
-
"model_path": "
|
17 |
"replacements": [('\n', '. ')]
|
18 |
},
|
19 |
"Español México | Claude": {
|
@@ -22,11 +22,9 @@ model_names = {
|
|
22 |
}
|
23 |
}
|
24 |
|
25 |
-
# Define la carpeta donde se guardarán los archivos
|
26 |
-
file_folder = '/home/app/'
|
27 |
-
|
28 |
# Comprueba si los modelos definidos existen en la carpeta de modelos
|
29 |
-
|
|
|
30 |
|
31 |
def multiple_replace(text, replacements):
|
32 |
# Iterar sobre cada par de remplazo
|
@@ -52,22 +50,14 @@ def convert_text_to_speech(text, model_name):
|
|
52 |
if filtered_text is None:
|
53 |
return None
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
app.logger.info("Audio file created at: %s", output_file)
|
58 |
-
piper_exe = os.path.join(file_folder, 'piper') # Ajusta la ruta para piper
|
59 |
-
|
60 |
-
if os.path.isfile(piper_exe):
|
61 |
-
comando = f'echo {filtered_text} | "{piper_exe}" -m {model_name} -f {output_file}'
|
62 |
-
subprocess.run(comando, shell=True)
|
63 |
-
return output_file
|
64 |
-
else:
|
65 |
-
return "No se encontró el archivo piper.exe en el directorio correcto."
|
66 |
|
67 |
@app.route('/')
|
68 |
def index():
|
69 |
-
model_options = existing_models
|
70 |
-
|
|
|
71 |
return render_template('index.html', model_options=model_options)
|
72 |
|
73 |
@app.route('/convert', methods=['POST'])
|
@@ -80,14 +70,11 @@ def convert_text():
|
|
80 |
def remove_file(response):
|
81 |
try:
|
82 |
os.remove(output_file)
|
83 |
-
|
84 |
except Exception as error:
|
85 |
-
|
86 |
return response
|
87 |
|
88 |
-
if output_file is None:
|
89 |
-
return "Error: No se pudo generar el archivo de audio."
|
90 |
-
|
91 |
with open(output_file, 'rb') as audio_file:
|
92 |
audio_content = audio_file.read()
|
93 |
|
|
|
13 |
# Define los nombres asignados a modelos específicos, en caso de no existir no se muestran
|
14 |
model_names = {
|
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": {
|
|
|
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
|
|
|
50 |
if filtered_text is None:
|
51 |
return None
|
52 |
|
53 |
+
# Define la carpeta donde se guardan los archivos
|
54 |
+
file_folder = '/home/app/'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
@app.route('/')
|
57 |
def index():
|
58 |
+
model_options = existing_models # Utiliza los modelos existentes
|
59 |
+
# Registra el contenido de la carpeta actual
|
60 |
+
logging.info("Contenido de la carpeta actual: %s", os.listdir(file_folder))
|
61 |
return render_template('index.html', model_options=model_options)
|
62 |
|
63 |
@app.route('/convert', methods=['POST'])
|
|
|
70 |
def remove_file(response):
|
71 |
try:
|
72 |
os.remove(output_file)
|
73 |
+
logging.info("Archivo de audio eliminado: %s", output_file)
|
74 |
except Exception as error:
|
75 |
+
logging.error("Error al eliminar el archivo: %s", error)
|
76 |
return response
|
77 |
|
|
|
|
|
|
|
78 |
with open(output_file, 'rb') as audio_file:
|
79 |
audio_content = audio_file.read()
|
80 |
|