aliabd HF staff commited on
Commit
99fe65c
1 Parent(s): 3524251

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -49
app.py CHANGED
@@ -6,62 +6,21 @@ from neon_tts_plugin_coqui import CoquiTTS
6
 
7
  # load the model and set up constants
8
  LANGUAGES = list(CoquiTTS.langs.keys())
9
- default_lang = "en"
10
- title = "🐸💬 - NeonAI Coqui AI TTS Plugin"
11
- description = "🐸💬 - a deep learning toolkit for Text-to-Speech, battle-tested in research and production"
12
- info = "more info at [Neon Coqui TTS Plugin](https://github.com/NeonGeckoCom/neon-tts-plugin-coqui), [Coqui TTS](https://github.com/coqui-ai/TTS)"
13
- badge = "https://visitor-badge-reloaded.herokuapp.com/badge?page_id=neongeckocom.neon-tts-plugin-coqui"
14
  coquiTTS = CoquiTTS()
15
 
16
  # define core fn
17
  def tts(text: str, language: str):
18
- print(text, language)
19
- # return output
20
  with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
21
  coquiTTS.get_tts(text, fp, speaker = {"language" : language})
22
  return fp.name
23
 
 
 
 
 
24
 
25
- # start a block
26
- with gr.Blocks() as blocks:
27
- # define text on page
28
- gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>"
29
- + title
30
- + "</h1>")
31
- gr.Markdown(description)
32
- # define layout
33
- with gr.Row():
34
- with gr.Column():
35
- # define inputs
36
- textbox = gr.Textbox(
37
- label="Input",
38
- value=CoquiTTS.langs[default_lang]["sentence"],
39
- max_lines=3,
40
- )
41
- radio = gr.Radio(
42
- label="Language",
43
- choices=LANGUAGES,
44
- value=default_lang
45
- )
46
- with gr.Row():
47
- # define button
48
- submit = gr.Button("Submit", variant="primary")
49
- # define output
50
- audio = gr.Audio(label="Output", interactive=False)
51
-
52
- gr.Markdown(info)
53
- gr.Markdown("<center>"
54
- +f'<img src={badge} alt="visitors badge"/>'
55
- +"</center>")
56
 
57
- # define what will run when submit is clicked
58
- submit.click(
59
- tts,
60
- [textbox, radio],
61
- [audio],
62
- )
63
- # define what will run when the radio input is changed
64
- radio.change(lambda lang: CoquiTTS.langs[lang]["sentence"], radio, textbox)
65
-
66
- # launch
67
- blocks.launch()
 
6
 
7
  # load the model and set up constants
8
  LANGUAGES = list(CoquiTTS.langs.keys())
 
 
 
 
 
9
  coquiTTS = CoquiTTS()
10
 
11
  # define core fn
12
  def tts(text: str, language: str):
 
 
13
  with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
14
  coquiTTS.get_tts(text, fp, speaker = {"language" : language})
15
  return fp.name
16
 
17
+ # define inputs and outputs
18
+ inputs = [gr.Textbox(label="Input", value=CoquiTTS.langs["en"]["sentence"], max_lines=3),
19
+ gr.Radio(label="Language", choices=LANGUAGES, value="en")]
20
+ outputs = gr.Audio(label="Output")
21
 
22
+ # define interface
23
+ demo = gr.Interface(fn=tts, inputs=inputs, outputs=outputs)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
+ # launch
26
+ demo.launch()