riabayonaor commited on
Commit
59898ad
1 Parent(s): 87dbfaa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -1,23 +1,25 @@
1
  import gradio as gr
2
- from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq
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 procesador
9
- model_name = "facebook/mms-tts-spa"
10
- processor = AutoProcessor.from_pretrained(model_name)
11
- model = AutoModelForSpeechSeq2Seq.from_pretrained(model_name)
12
 
13
  inputs = processor(text, return_tensors="pt")
14
  with torch.no_grad():
15
- speech = model.generate(**inputs)
16
 
17
- waveform = processor.decode(speech.cpu().numpy(), skip_special_tokens=True)
18
 
19
- output_path = "/tmp/output.wav"
20
- scipy.io.wavfile.write(output_path, model.config.sampling_rate, np.array(waveform))
 
 
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.Audio(type="filepath"), gr.File()],
29
  title="Spanish Text-to-Speech",
30
- description="Convert text to speech in Spanish using the facebook/mms-tts-spa model."
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()