Spaces:
Runtime error
Runtime error
riabayonaor
commited on
Commit
•
59898ad
1
Parent(s):
87dbfaa
Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,25 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import
|
3 |
import torch
|
4 |
import scipy.io.wavfile
|
5 |
import numpy as np
|
6 |
|
7 |
def text_to_speech(text):
|
8 |
-
# Cargar el modelo y el
|
9 |
-
model_name = "facebook/
|
10 |
-
processor =
|
11 |
-
model =
|
12 |
|
13 |
inputs = processor(text, return_tensors="pt")
|
14 |
with torch.no_grad():
|
15 |
-
|
16 |
|
17 |
-
|
18 |
|
19 |
-
|
20 |
-
|
|
|
|
|
21 |
|
22 |
return output_path, output_path
|
23 |
|
@@ -25,9 +27,9 @@ def text_to_speech(text):
|
|
25 |
iface = gr.Interface(
|
26 |
fn=text_to_speech,
|
27 |
inputs="text",
|
28 |
-
outputs=[gr.
|
29 |
title="Spanish Text-to-Speech",
|
30 |
-
description="Convert text to speech in Spanish using the facebook/
|
31 |
)
|
32 |
|
33 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
import torch
|
4 |
import scipy.io.wavfile
|
5 |
import numpy as np
|
6 |
|
7 |
def text_to_speech(text):
|
8 |
+
# Cargar el modelo y el tokenizador
|
9 |
+
model_name = "facebook/tts_transformer-es-css10"
|
10 |
+
processor = AutoTokenizer.from_pretrained(model_name)
|
11 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
12 |
|
13 |
inputs = processor(text, return_tensors="pt")
|
14 |
with torch.no_grad():
|
15 |
+
generated_ids = model.generate(inputs.input_ids)
|
16 |
|
17 |
+
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
18 |
|
19 |
+
# Aquí podrías generar un archivo de audio a partir del texto generado si tuvieras una función para ello
|
20 |
+
output_path = "/tmp/output.txt"
|
21 |
+
with open(output_path, "w") as f:
|
22 |
+
f.write(generated_text)
|
23 |
|
24 |
return output_path, output_path
|
25 |
|
|
|
27 |
iface = gr.Interface(
|
28 |
fn=text_to_speech,
|
29 |
inputs="text",
|
30 |
+
outputs=[gr.Textbox(), gr.File()],
|
31 |
title="Spanish Text-to-Speech",
|
32 |
+
description="Convert text to speech in Spanish using the facebook/tts_transformer-es-css10 model."
|
33 |
)
|
34 |
|
35 |
iface.launch()
|