Abhinay45 commited on
Commit
0c47ca5
1 Parent(s): 06b111a

Upload 4 files

Browse files
Files changed (4) hide show
  1. README.md +6 -7
  2. app.py +171 -0
  3. gitattributes +35 -0
  4. requirements.txt +2 -0
README.md CHANGED
@@ -1,13 +1,12 @@
1
  ---
2
- title: SML Emotional TTS
3
- emoji: 🚀
4
- colorFrom: blue
5
- colorTo: gray
6
  sdk: gradio
7
- sdk_version: 4.37.1
8
  app_file: app.py
9
  pinned: false
10
- license: mit
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: Parler TTS Expresso
3
+ emoji:
4
+ colorFrom: red
5
+ colorTo: blue
6
  sdk: gradio
7
+ sdk_version: 4.31.2
8
  app_file: app.py
9
  pinned: false
 
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import spaces
2
+ import gradio as gr
3
+ import torch
4
+ from transformers.models.speecht5.number_normalizer import EnglishNumberNormalizer
5
+ from string import punctuation
6
+ import re
7
+
8
+ from parler_tts import ParlerTTSForConditionalGeneration
9
+ from transformers import AutoTokenizer, AutoFeatureExtractor, set_seed
10
+
11
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
12
+
13
+ repo_id = "parler-tts/parler-tts-mini-expresso"
14
+
15
+ model = ParlerTTSForConditionalGeneration.from_pretrained(repo_id).to(device)
16
+ tokenizer = AutoTokenizer.from_pretrained(repo_id)
17
+ feature_extractor = AutoFeatureExtractor.from_pretrained(repo_id)
18
+
19
+ SAMPLE_RATE = feature_extractor.sampling_rate
20
+ SEED = 42
21
+
22
+ default_text = "*Remember* - this is only the first iteration of the model! To improve the prosody and naturalness of the speech further, we're scaling up the amount of training data by a factor of *five times*."
23
+ default_description = "Thomas speaks with emphasis and excitement at a moderate pace with high quality."
24
+ examples = [
25
+ [
26
+ "Remember - this is only the first iteration of the model. To improve the prosody and naturalness of the speech further, we're scaling up the amount of training data by a factor of five times.",
27
+ "Thomas speaks in a sad tone at a moderate pace with high quality."
28
+ ],
29
+ [
30
+ "Did you know? You can reproduce this entire training recipe by following the steps outlined on the model card!",
31
+ "Talia speaks quickly with excitement and high quality audio.",
32
+ ],
33
+ [
34
+ "But that's no secret! The entire project is open source first, with all release artefacts on the Hub.",
35
+ "Elisabeth speaks happily at a slightly slower than average pace with high quality audio.",
36
+ ],
37
+ [
38
+ "Hey there! I'm Jerry. Or at least I think I am? I just need to check that quickly.",
39
+ "Jerry speaks in a confused tone at a moderately slow pace with high quality audio.",
40
+ ],
41
+ [
42
+ "<laugh> It can even laugh! Do you believe it ? I don't!",
43
+ "Talia speaks with laughter with high quality.",
44
+ ],
45
+ ]
46
+
47
+ number_normalizer = EnglishNumberNormalizer()
48
+
49
+
50
+ def preprocess(text):
51
+ text = number_normalizer(text).strip()
52
+ if text[-1] not in punctuation:
53
+ text = f"{text}."
54
+
55
+ abbreviations_pattern = r'\b[A-Z][A-Z\.]+\b'
56
+
57
+ def separate_abb(chunk):
58
+ chunk = chunk.replace(".", "")
59
+ print(chunk)
60
+ return " ".join(chunk)
61
+
62
+ abbreviations = re.findall(abbreviations_pattern, text)
63
+ for abv in abbreviations:
64
+ if abv in text:
65
+ text = text.replace(abv, separate_abb(abv))
66
+ return text
67
+
68
+
69
+ @spaces.GPU
70
+ def gen_tts(text, description):
71
+ inputs = tokenizer(description, return_tensors="pt").to(device)
72
+ prompt = tokenizer(preprocess(text), return_tensors="pt").to(device)
73
+
74
+ set_seed(SEED)
75
+ generation = model.generate(input_ids=inputs.input_ids, prompt_input_ids=prompt.input_ids)
76
+ audio_arr = generation.cpu().numpy().squeeze()
77
+
78
+ return SAMPLE_RATE, audio_arr
79
+
80
+
81
+ css = """
82
+ #share-btn-container {
83
+ display: flex;
84
+ padding-left: 0.5rem !important;
85
+ padding-right: 0.5rem !important;
86
+ background-color: #000000;
87
+ justify-content: center;
88
+ align-items: center;
89
+ border-radius: 9999px !important;
90
+ width: 13rem;
91
+ margin-top: 10px;
92
+ margin-left: auto;
93
+ flex: unset !important;
94
+ }
95
+ #share-btn {
96
+ all: initial;
97
+ color: #ffffff;
98
+ font-weight: 600;
99
+ cursor: pointer;
100
+ font-family: 'IBM Plex Sans', sans-serif;
101
+ margin-left: 0.5rem !important;
102
+ padding-top: 0.25rem !important;
103
+ padding-bottom: 0.25rem !important;
104
+ right:0;
105
+ }
106
+ #share-btn * {
107
+ all: unset !important;
108
+ }
109
+ #share-btn-container div:nth-child(-n+2){
110
+ width: auto !important;
111
+ min-height: 0px !important;
112
+ }
113
+ #share-btn-container .wrap {
114
+ display: none !important;
115
+ }
116
+ """
117
+ with gr.Blocks(css=css) as block:
118
+ gr.HTML(
119
+ """
120
+ <div style="text-align: center; max-width: 700px; margin: 0 auto;">
121
+ <div
122
+ style="
123
+ display: inline-flex; align-items: center; gap: 0.8rem; font-size: 1.75rem;
124
+ "
125
+ >
126
+ <h1 style="font-weight: 900; margin-bottom: 7px; line-height: normal;">
127
+ Parler-TTS: Expresso ☕️️
128
+ </h1>
129
+ </div>
130
+ </div>
131
+ """
132
+ )
133
+ gr.HTML(
134
+ f"""
135
+ <p><a href="https://huggingface.co/parler-tts/parler-tts-mini-expresso"> Parler-TTS Mini: Expresso</a>
136
+ is a text-to-speech (TTS) model fine-tuned on the <a href="https://huggingface.co/datasets/ylacombe/expresso"> Expresso dataset</a>.
137
+ It generates high-quality speech in a given <b>emotion</b> and <b>voice</b> that can be controlled through a simple text prompt.</p>
138
+
139
+ <p>Tips for ensuring good generation:
140
+ <ul>
141
+ <li>Specify the name of a male speaker (Jerry, Thomas) or female speaker (Talia, Elisabeth) for consistent voices</li>
142
+ <li>The model can generate in a range of emotions, including: "happy", "confused", "default" (meaning no particular emotion conveyed), "laughing", "sad", "whisper", "emphasis"</li>
143
+ <li>Punctuation can be used to control the prosody of the generations, e.g. use commas to add small breaks in speech</li>
144
+ <li>To emphasise particular words, wrap them in asterisk (e.g. *you* in the example above) and include "emphasis" in the prompt</li>
145
+ </ul>
146
+ </p>
147
+ """
148
+ )
149
+ with gr.Row():
150
+ with gr.Column():
151
+ input_text = gr.Textbox(label="Input Text", lines=2, value=default_text, elem_id="input_text")
152
+ description = gr.Textbox(label="Description", lines=2, value=default_description, elem_id="input_description")
153
+ run_button = gr.Button("Generate Audio", variant="primary")
154
+ with gr.Column():
155
+ audio_out = gr.Audio(label="Parler-TTS generation", type="numpy", elem_id="audio_out")
156
+
157
+ inputs = [input_text, description]
158
+ outputs = [audio_out]
159
+ gr.Examples(examples=examples, fn=gen_tts, inputs=inputs, outputs=outputs, cache_examples=True)
160
+ run_button.click(fn=gen_tts, inputs=inputs, outputs=outputs, queue=True)
161
+ gr.HTML(
162
+ """
163
+ <p>To improve the prosody and naturalness of the speech further, we're scaling up the amount of training data to 50k hours of speech.
164
+ The v1 release of the model will be trained on this data, as well as inference optimisations, such as flash attention
165
+ and torch compile, that will improve the latency by 2-4x. If you want to find out more about how this model was trained and even fine-tune it yourself, check-out the
166
+ <a href="https://github.com/huggingface/parler-tts"> Parler-TTS</a> repository on GitHub. The Parler-TTS codebase and its associated checkpoints are licensed under <a href='https://github.com/huggingface/parler-tts?tab=Apache-2.0-1-ov-file#readme'> Apache 2.0</a>.</p>
167
+ """
168
+ )
169
+
170
+ block.queue()
171
+ block.launch(share=True)
gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ git+https://github.com/huggingface/parler-tts.git
2
+ accelerate