Simonlob commited on
Commit
589b079
·
1 Parent(s): 702ba50

.pt speakers map

Browse files
Files changed (4) hide show
  1. app.py +20 -5
  2. examples.yaml +14 -7
  3. speakers/speaker_map.json +9 -0
  4. util.py +6 -7
app.py CHANGED
@@ -7,6 +7,7 @@ import gradio as gr
7
  from util import InitModels, load_config, Examples
8
  import numpy as np
9
  import torch
 
10
 
11
  config = load_config("./model_config.yaml")
12
  models_configs = config.models
@@ -18,9 +19,13 @@ examples = examples_maker()
18
  init_models = InitModels(models_configs)
19
  models = init_models()
20
 
 
 
 
 
21
 
22
  @spaces.GPU
23
- def generate_speech_gpu(text, model_choice, t, top_p, rp):
24
  """
25
  Generate speech from text using the selected model on GPU
26
  """
@@ -37,9 +42,13 @@ def generate_speech_gpu(text, model_choice, t, top_p, rp):
37
 
38
  selected_model = models[model_choice]
39
 
 
 
 
40
  print(f"Generating speech with {model_choice}...")
41
  audio, _ = selected_model(
42
  text,
 
43
  temperature=t,
44
  top_p=top_p,
45
  repetition_penalty=rp
@@ -67,6 +76,12 @@ with gr.Blocks(title="😻 KaniTTS - Text to Speech", theme=gr.themes.Ocean()) a
67
  label="Selected Model"
68
  )
69
 
 
 
 
 
 
 
70
  text_input = gr.Textbox(
71
  label="Text",
72
  placeholder="Enter your text ...",
@@ -87,7 +102,7 @@ with gr.Blocks(title="😻 KaniTTS - Text to Speech", theme=gr.themes.Ocean()) a
87
  minimum=1.0, maximum=2.0, value=1.1, step=0.05,
88
  label="Repetition Penalty",
89
  )
90
-
91
  generate_btn = gr.Button("Run", variant="primary", size="lg")
92
 
93
 
@@ -100,17 +115,17 @@ with gr.Blocks(title="😻 KaniTTS - Text to Speech", theme=gr.themes.Ocean()) a
100
  # GPU generation event
101
  generate_btn.click(
102
  fn=generate_speech_gpu,
103
- inputs=[text_input, model_dropdown, temp, top_p, rp],
104
  outputs=[audio_output]
105
  )
106
-
107
  with gr.Row():
108
 
109
  examples = examples
110
 
111
  gr.Examples(
112
  examples=examples,
113
- inputs=[text_input, model_dropdown, temp, top_p, rp],
114
  fn=generate_speech_gpu,
115
  outputs=[audio_output],
116
  cache_examples=True,
 
7
  from util import InitModels, load_config, Examples
8
  import numpy as np
9
  import torch
10
+ import json
11
 
12
  config = load_config("./model_config.yaml")
13
  models_configs = config.models
 
19
  init_models = InitModels(models_configs)
20
  models = init_models()
21
 
22
+ # Load speaker map
23
+ with open("./speakers/speaker_map.json", "r") as f:
24
+ speaker_map = json.load(f)
25
+
26
 
27
  @spaces.GPU
28
+ def generate_speech_gpu(text, model_choice, speaker_choice, t, top_p, rp):
29
  """
30
  Generate speech from text using the selected model on GPU
31
  """
 
42
 
43
  selected_model = models[model_choice]
44
 
45
+ # Get speaker embedding path
46
+ speaker_emb = speaker_map.get(speaker_choice) if speaker_choice else None
47
+
48
  print(f"Generating speech with {model_choice}...")
49
  audio, _ = selected_model(
50
  text,
51
+ speaker_emb=speaker_emb,
52
  temperature=t,
53
  top_p=top_p,
54
  repetition_penalty=rp
 
76
  label="Selected Model"
77
  )
78
 
79
+ speaker_dropdown = gr.Dropdown(
80
+ choices=list(speaker_map.keys()),
81
+ value=list(speaker_map.keys())[0],
82
+ label="Speaker"
83
+ )
84
+
85
  text_input = gr.Textbox(
86
  label="Text",
87
  placeholder="Enter your text ...",
 
102
  minimum=1.0, maximum=2.0, value=1.1, step=0.05,
103
  label="Repetition Penalty",
104
  )
105
+
106
  generate_btn = gr.Button("Run", variant="primary", size="lg")
107
 
108
 
 
115
  # GPU generation event
116
  generate_btn.click(
117
  fn=generate_speech_gpu,
118
+ inputs=[text_input, model_dropdown, speaker_dropdown, temp, top_p, rp],
119
  outputs=[audio_output]
120
  )
121
+
122
  with gr.Row():
123
 
124
  examples = examples
125
 
126
  gr.Examples(
127
  examples=examples,
128
+ inputs=[text_input, model_dropdown, speaker_dropdown, temp, top_p, rp],
129
  fn=generate_speech_gpu,
130
  outputs=[audio_output],
131
  cache_examples=True,
examples.yaml CHANGED
@@ -1,21 +1,24 @@
1
  examples:
2
  - text: >-
3
  No, that does not make you a failure. No, sweetie, no. It just, uh, it just means that you're having a tough time...
4
- model: "test-135000"
 
5
  temperature: 1
6
  top_p: 0.95
7
  repetition_penalty: 1.1
8
 
9
  - text: >-
10
  Anyway, um, so, um, tell me, tell me all about her. I mean, what's she like? Is she really, you know, pretty?
11
- model: "test-135000"
 
12
  temperature: 1
13
  top_p: 0.95
14
  repetition_penalty: 1.1
15
 
16
  - text: >-
17
  Have some wine, the March Hare said in an encouraging tone. Alice looked all round the table, but there was nothing on it but tea. I don't see any wine, she remarked. There isn't any, said the March Hare. Then it wasn't very civil of you to offer it, said Alice angrily. It wasn't very civil of you to sit down without being invited, said the March Hare. I didn't know it was YOUR table, said Alice; it's laid for a great many more than three. Your hair wants cutting, said the Hatter. He had been looking at Alice for some time with great curiosity, and this was his first speech. You should learn not to make personal remarks, Alice said with some severity; it's very rude.
18
- model: "test-135000"
 
19
  temperature: 1
20
  top_p: 0.95
21
  repetition_penalty: 1.1
@@ -23,21 +26,24 @@ examples:
23
 
24
  - text: >-
25
  Attention networks have proven to be an effective approach for embedding categorical inference within a deep neural network. However, for many tasks we may want to model richer structural dependencies without abandoning end-to-end training. In this work, we experiment with incorporating richer structural distributions, encoded using graphical models, within deep networks. We show that these structured attention networks are simple extensions of the basic attention procedure, and that they allow for extending attention beyond the standard softselection approach, such as attending to partial segmentations or to subtrees.
26
- model: "test-135000"
 
27
  temperature: 1
28
  top_p: 0.95
29
  repetition_penalty: 1.1
30
 
31
  - text: >-
32
  Кыргыз жери! Сенин ар бир ташыңда, ар бир тооңдо, ар бир сууңда менин жүрөгүмдүн бир бөлүгү бар. Сен менин ата-журтум, менин ыйык мекенимсиң.
33
- model: "test-135000"
 
34
  temperature: 1
35
  top_p: 0.95
36
  repetition_penalty: 1.1
37
 
38
  - text: >-
39
  Өлкө башчынын айтымында, айдоочулук күбөлүктөрдү алмаштыруу чечими коопсуздук жана мамлекеттин эл аралык аброю үчүн кабыл алынган. Анткени мурда чет өлкөлөрдө чыгарылган эски үлгүдөгү документтердин коргоо деңгээли алсыз болуп, жасалмалоо фактылары кеңири тараган. Айрым жасалма ID-паспорттор жана айдоочулук күбөлүктөр менен кылмышка, атүгүл террорчулукка байланышкан учурлар катталып, бул Кыргызстанга олуттуу имидждик зыян келтирген.
40
- model: "test-135000"
 
41
  temperature: 1
42
  top_p: 0.95
43
  repetition_penalty: 1.1
@@ -45,7 +51,8 @@ examples:
45
 
46
  - text: >-
47
  ¡Qué alegría volver a verte después de tanto tiempo!
48
- model: "test-135000"
 
49
  temperature: 1
50
  top_p: 0.95
51
  repetition_penalty: 1.1
 
1
  examples:
2
  - text: >-
3
  No, that does not make you a failure. No, sweetie, no. It just, uh, it just means that you're having a tough time...
4
+ model: "Exp-1"
5
+ speaker: "Kore (en)"
6
  temperature: 1
7
  top_p: 0.95
8
  repetition_penalty: 1.1
9
 
10
  - text: >-
11
  Anyway, um, so, um, tell me, tell me all about her. I mean, what's she like? Is she really, you know, pretty?
12
+ model: "Exp-1"
13
+ speaker: "Andrew (en)"
14
  temperature: 1
15
  top_p: 0.95
16
  repetition_penalty: 1.1
17
 
18
  - text: >-
19
  Have some wine, the March Hare said in an encouraging tone. Alice looked all round the table, but there was nothing on it but tea. I don't see any wine, she remarked. There isn't any, said the March Hare. Then it wasn't very civil of you to offer it, said Alice angrily. It wasn't very civil of you to sit down without being invited, said the March Hare. I didn't know it was YOUR table, said Alice; it's laid for a great many more than three. Your hair wants cutting, said the Hatter. He had been looking at Alice for some time with great curiosity, and this was his first speech. You should learn not to make personal remarks, Alice said with some severity; it's very rude.
20
+ model: "Exp-1"
21
+ speaker: "Andrew (en)"
22
  temperature: 1
23
  top_p: 0.95
24
  repetition_penalty: 1.1
 
26
 
27
  - text: >-
28
  Attention networks have proven to be an effective approach for embedding categorical inference within a deep neural network. However, for many tasks we may want to model richer structural dependencies without abandoning end-to-end training. In this work, we experiment with incorporating richer structural distributions, encoded using graphical models, within deep networks. We show that these structured attention networks are simple extensions of the basic attention procedure, and that they allow for extending attention beyond the standard softselection approach, such as attending to partial segmentations or to subtrees.
29
+ model: "Exp-1"
30
+ speaker: "Andrew (en)"
31
  temperature: 1
32
  top_p: 0.95
33
  repetition_penalty: 1.1
34
 
35
  - text: >-
36
  Кыргыз жери! Сенин ар бир ташыңда, ар бир тооңдо, ар бир сууңда менин жүрөгүмдүн бир бөлүгү бар. Сен менин ата-журтум, менин ыйык мекенимсиң.
37
+ model: "Exp-1"
38
+ speaker: "Aisulu (ky)"
39
  temperature: 1
40
  top_p: 0.95
41
  repetition_penalty: 1.1
42
 
43
  - text: >-
44
  Өлкө башчынын айтымында, айдоочулук күбөлүктөрдү алмаштыруу чечими коопсуздук жана мамлекеттин эл аралык аброю үчүн кабыл алынган. Анткени мурда чет өлкөлөрдө чыгарылган эски үлгүдөгү документтердин коргоо деңгээли алсыз болуп, жасалмалоо фактылары кеңири тараган. Айрым жасалма ID-паспорттор жана айдоочулук күбөлүктөр менен кылмышка, атүгүл террорчулукка байланышкан учурлар катталып, бул Кыргызстанга олуттуу имидждик зыян келтирген.
45
+ model: "Exp-1"
46
+ speaker: "Baike (ky)"
47
  temperature: 1
48
  top_p: 0.95
49
  repetition_penalty: 1.1
 
51
 
52
  - text: >-
53
  ¡Qué alegría volver a verte después de tanto tiempo!
54
+ model: "Exp-1"
55
+ speaker: "Nova (es)"
56
  temperature: 1
57
  top_p: 0.95
58
  repetition_penalty: 1.1
speakers/speaker_map.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "Kore (en)": "./speakers/speaker_1.pt",
3
+ "Puck (en)": "./speakers/speaker_2.pt",
4
+ "Andrew (en)": "./speakers/speaker_3.pt",
5
+ "Aisulu (ky)": "./speakers/speaker_4.pt",
6
+ "Baike (ky)": "./speakers/speaker_5.pt",
7
+ "Ash (es)": "./speakers/speaker_6.pt",
8
+ "Nova (es)": "./speakers/speaker_7.pt"
9
+ }
util.py CHANGED
@@ -1,4 +1,5 @@
1
  from kani_tts import KaniTTS
 
2
 
3
  import os
4
  from omegaconf import OmegaConf
@@ -56,9 +57,6 @@ class InitModels:
56
  models[model_name] = KaniTTS(
57
  model_name=cfg_dict.get('model_name'),
58
  device_map=cfg_dict.get('device_map'),
59
- use_bematts=cfg_dict.get('use_bematts', False),
60
- audio_step=cfg_dict.get('audio_step', 1.0),
61
- use_learnable_rope=cfg_dict.get('use_learnable_rope', False)
62
  )
63
  print(f"{model_name} loaded!")
64
  print("All models loaded!")
@@ -73,13 +71,13 @@ class Examples:
73
  ----------
74
  exam_cfg : OmegaConf | DictConfig
75
  Parsed contents of `examples.yaml`. Expected structure:
76
- `examples: [ {text, model, temperature?, top_p?, repetition_penalty?}, ... ]`.
77
 
78
  Behavior
79
  --------
80
  - Produces a list-of-lists whose order must match the `inputs` order
81
  used when constructing `gr.Examples` in `app.py`.
82
- - Current order: `[text, model_dropdown, temp, top_p, rp]`.
83
 
84
  Why this exists
85
  ---------------
@@ -95,11 +93,12 @@ class Examples:
95
  for e in self.exam_cfg.examples:
96
  text = e.get("text")
97
  model = e.get("model")
 
98
  temperature = e.get("temperature", 1.0)
99
  top_p = e.get("top_p", 0.95)
100
  repetition_penalty = e.get("repetition_penalty", 1.1)
101
- # Order must match gr.Examples inputs: [text, model_dropdown, temp, top_p, rp]
102
- rows.append([text, model, temperature, top_p, repetition_penalty])
103
 
104
  return rows
105
 
 
1
  from kani_tts import KaniTTS
2
+ from kani_tts import SpeakerEmbedder
3
 
4
  import os
5
  from omegaconf import OmegaConf
 
57
  models[model_name] = KaniTTS(
58
  model_name=cfg_dict.get('model_name'),
59
  device_map=cfg_dict.get('device_map'),
 
 
 
60
  )
61
  print(f"{model_name} loaded!")
62
  print("All models loaded!")
 
71
  ----------
72
  exam_cfg : OmegaConf | DictConfig
73
  Parsed contents of `examples.yaml`. Expected structure:
74
+ `examples: [ {text, model, speaker?, temperature?, top_p?, repetition_penalty?}, ... ]`.
75
 
76
  Behavior
77
  --------
78
  - Produces a list-of-lists whose order must match the `inputs` order
79
  used when constructing `gr.Examples` in `app.py`.
80
+ - Current order: `[text, model_dropdown, speaker_dropdown, temp, top_p, rp]`.
81
 
82
  Why this exists
83
  ---------------
 
93
  for e in self.exam_cfg.examples:
94
  text = e.get("text")
95
  model = e.get("model")
96
+ speaker = e.get("speaker", "Kore (en)")
97
  temperature = e.get("temperature", 1.0)
98
  top_p = e.get("top_p", 0.95)
99
  repetition_penalty = e.get("repetition_penalty", 1.1)
100
+ # Order must match gr.Examples inputs: [text, model_dropdown, speaker_dropdown, temp, top_p, rp]
101
+ rows.append([text, model, speaker, temperature, top_p, repetition_penalty])
102
 
103
  return rows
104