sanchit-gandhi HF staff commited on
Commit
c36d1d0
1 Parent(s): f4cce0d

create demo

Browse files
Files changed (3) hide show
  1. README.md +1 -1
  2. app.py +173 -0
  3. requirements.txt +2 -0
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: Parler Tts Expresso V0.1
3
  emoji: 📉
4
  colorFrom: red
5
  colorTo: red
 
1
  ---
2
+ title: Parler TTS: Expresso v0.1
3
  emoji: 📉
4
  colorFrom: red
5
  colorTo: red
app.py ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # TODO(SG): update to the latest checkpoint
14
+ repo_id = "reach-vb/parler-tts-expresso-mistral-v0.1"
15
+
16
+ model = ParlerTTSForConditionalGeneration.from_pretrained(repo_id).to(device)
17
+ tokenizer = AutoTokenizer.from_pretrained(repo_id)
18
+ feature_extractor = AutoFeatureExtractor.from_pretrained(repo_id)
19
+
20
+ SAMPLE_RATE = feature_extractor.sampling_rate
21
+ SEED = 42
22
+
23
+ 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*."
24
+ default_description = "Thomas speaks with emphasis at a moderate pace with high quality."
25
+ examples = [
26
+ [
27
+ "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.",
28
+ "Thomas speaks sadly at a very slow pace with high quality."
29
+ ],
30
+ [
31
+ "Shhh! Did you know? You can reproduce this entire training recipe by following the steps outlined on the model card. It only takes one hour to train!",
32
+ "Talia whispers quickly with high quality audio.",
33
+ ],
34
+ [
35
+ "But that's no secret! The entire project is open-source first. We are releasing all datasets, training and inference code, so that you can use them yourself!",
36
+ "Elisabeth speaks happily at a slightly slower than average pace with high quality audio.",
37
+ ],
38
+ [
39
+ "Hey there. I'm Jerry. Or at least, I *think* I am? I just need to check that quickly.",
40
+ "Jerry speaks in a confused tone at a moderate pace with high quality audio.",
41
+ ],
42
+ ]
43
+
44
+ number_normalizer = EnglishNumberNormalizer()
45
+
46
+
47
+ def preprocess(text):
48
+ text = number_normalizer(text).strip()
49
+ text = text.replace("-", " ")
50
+ if text[-1] not in punctuation:
51
+ text = f"{text}."
52
+
53
+ abbreviations_pattern = r'\b[A-Z][A-Z\.]+\b'
54
+
55
+ def separate_abb(chunk):
56
+ chunk = chunk.replace(".", "")
57
+ print(chunk)
58
+ return " ".join(chunk)
59
+
60
+ abbreviations = re.findall(abbreviations_pattern, text)
61
+ for abv in abbreviations:
62
+ if abv in text:
63
+ text = text.replace(abv, separate_abb(abv))
64
+ return text
65
+
66
+
67
+ @spaces.GPU
68
+ def gen_tts(text, description):
69
+ inputs = tokenizer(description, return_tensors="pt").to(device)
70
+ prompt = tokenizer(preprocess(text), return_tensors="pt").to(device)
71
+
72
+ set_seed(SEED)
73
+ generation = model.generate(
74
+ input_ids=inputs.input_ids, prompt_input_ids=prompt.input_ids, do_sample=True, temperature=1.0
75
+ )
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 v0.1 ☕️️
128
+ </h1>
129
+ </div>
130
+ </div>
131
+ """
132
+ )
133
+ gr.HTML(
134
+ f"""
135
+ <p><a href="https://github.com/huggingface/parler-tts"> Parler-TTS</a> is a training and inference library for
136
+ high-fidelity text-to-speech (TTS) models. The model demonstrated here, <a href="https://huggingface.co/parler-tts/parler_tts_mini_expresso_v0.1"> Parler-TTS Mini: Expresso v0.1</a>,
137
+ is fine-tuned on the <a href="https://huggingface.co/datasets/ylacombe/expresso"> Expresso dataset</a>.
138
+ 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>
139
+
140
+ <p>Tips for ensuring good generation:
141
+ <ul>
142
+ <li>Specify the name of a male speaker (Jerry, Thomas) or female speaker (Talia, Elisabeth) for consistent voices</li>
143
+ <li>The model can generate in a range of emotions, including: "happy", "confused", "default" (meaning no particular emotion conveyed), "laughing", "sad", "whisper", "emphasis"</li>
144
+ <li>Include the term "high quality audio" to generate the highest quality audio, and "very noisy audio" for high levels of background noise</li>
145
+ <li>Punctuation can be used to control the prosody of the generations, e.g. use commas to add small breaks in speech</li>
146
+ <li>Wrap words in asterisk to emphasise them (e.g. `*Remember*` in the example below)</li>
147
+ </ul>
148
+ </p>
149
+ """
150
+ )
151
+ with gr.Row():
152
+ with gr.Column():
153
+ input_text = gr.Textbox(label="Input Text", lines=2, value=default_text, elem_id="input_text")
154
+ description = gr.Textbox(label="Description", lines=2, value=default_description, elem_id="input_description")
155
+ run_button = gr.Button("Generate Audio", variant="primary")
156
+ with gr.Column():
157
+ audio_out = gr.Audio(label="Parler-TTS generation", type="numpy", elem_id="audio_out")
158
+
159
+ inputs = [input_text, description]
160
+ outputs = [audio_out]
161
+ gr.Examples(examples=examples, fn=gen_tts, inputs=inputs, outputs=outputs, cache_examples=True)
162
+ run_button.click(fn=gen_tts, inputs=inputs, outputs=outputs, queue=True)
163
+ gr.HTML(
164
+ """
165
+ <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.
166
+ The v1 release of the model will be trained on this data, as well as inference optimisations, such as flash attention
167
+ 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
168
+ <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>
169
+ """
170
+ )
171
+
172
+ block.queue()
173
+ block.launch(share=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ git+https://github.com/huggingface/parler-tts.git
2
+ accelerate