ccoreilly commited on
Commit
7f0cc16
1 Parent(s): 89cf23f

Add gradio app

Browse files
Files changed (3) hide show
  1. Dockerfile +7 -1
  2. app.py +77 -0
  3. requirements.txt +2 -0
Dockerfile CHANGED
@@ -10,5 +10,11 @@ RUN cd espeak-ng && \
10
  make && \
11
  make install
12
 
13
- RUN espeak-ng "Bon dia" --ipa -v ca -q
 
14
 
 
 
 
 
 
 
10
  make && \
11
  make install
12
 
13
+ COPY requirements.txt .
14
+ COPY app.py .
15
 
16
+ RUN pip install -r requirements.txt
17
+
18
+ EXPOSE 7860
19
+
20
+ CMD python app.py
app.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tempfile
2
+ from typing import Optional
3
+ from TTS.config import load_config
4
+ import gradio as gr
5
+ import numpy as np
6
+ import os
7
+ import json
8
+ from TTS.utils.manage import ModelManager
9
+ from TTS.utils.synthesizer import Synthesizer
10
+
11
+
12
+ MAX_TXT_LEN = 100
13
+
14
+ SPEAKERS = ['f_cen_05', 'f_cen_81', 'f_occ_31', 'f_occ_de', 'f_sep_31', 'm_cen_08', 'm_occ_44', 'm_val_89']
15
+
16
+ def tts(text, speaker_idx):
17
+ if len(text) > MAX_TXT_LEN:
18
+ text = text[:MAX_TXT_LEN]
19
+ print(f"Input text was cutoff since it went over the {MAX_TXT_LEN} character limit.")
20
+ print(text)
21
+
22
+ model_path = os.getcwd() + "/best_model.pth"
23
+ config_path = os.getcwd() + "/config.json"
24
+ speakers_file_path = os.getcwd() + "/speakers.pth"
25
+ speakers_maping_path = os.getcwd() + "/speaker_map.json"
26
+ vocoder_path = None
27
+ vocoder_config_path = None
28
+
29
+ synthesizer = Synthesizer(
30
+ model_path, config_path, speakers_file_path, None, vocoder_path, vocoder_config_path,
31
+ )
32
+
33
+ # Map speaker aliases to speaker ids
34
+ with open(speakers_maping_path, 'r') as fp:
35
+ maping = json.load(fp)
36
+
37
+ speaker_idx = maping[speaker_idx]
38
+
39
+ # synthesize
40
+ if synthesizer is None:
41
+ raise NameError("model not found")
42
+ wavs = synthesizer.tts(text, speaker_idx)
43
+ # return output
44
+ with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
45
+ synthesizer.save_wav(wavs, fp)
46
+ return fp.name
47
+
48
+
49
+ description="""
50
+ 1️⃣ Introdueix el text a sintetitzar.
51
+
52
+ 2️⃣ Selecciona una veu en el desplegable.
53
+
54
+ 3️⃣ Gaudeix!
55
+ """
56
+ article= ""
57
+
58
+ iface = gr.Interface(
59
+ fn=tts,
60
+ inputs=[
61
+ gr.inputs.Textbox(
62
+ label="Text",
63
+ default="L'Èlia i l'Alí a l'aula. L'oli i l'ou. Lulú olorava la lila.",
64
+ ),
65
+ gr.inputs.Dropdown(label="Selecciona un parlant", choices=SPEAKERS, default=None)
66
+ ],
67
+ outputs=gr.outputs.Audio(label="Output",type="filepath"),
68
+ title="🗣️ TTS Català Multi Parlant - VITS 🗣️",
69
+ theme="grass",
70
+ description=description,
71
+ article=article,
72
+ allow_flagging="never",
73
+ flagging_options=['error', 'bad-quality', 'wrong-pronounciation'],
74
+ layout="vertical",
75
+ live=False
76
+ )
77
+ iface.launch(share=False)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ git+https://github.com/coqui-ai/TTS@dev#egg=TTS
2
+ gradio