CEHB commited on
Commit
a581dbd
1 Parent(s): c76703d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -30
app.py CHANGED
@@ -6,7 +6,7 @@ import torch
6
  from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan
7
 
8
 
9
- checkpoint = "microsoft/speecht5_tts"
10
  processor = SpeechT5Processor.from_pretrained(checkpoint)
11
  model = SpeechT5ForTextToSpeech.from_pretrained(checkpoint)
12
  vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
@@ -31,23 +31,7 @@ def predict(text, speaker):
31
  input_ids = inputs["input_ids"]
32
  input_ids = input_ids[..., :model.config.max_text_positions]
33
 
34
- if speaker == "Surprise Me!":
35
- # load one of the provided speaker embeddings at random
36
- idx = np.random.randint(len(speaker_embeddings))
37
- key = list(speaker_embeddings.keys())[idx]
38
- speaker_embedding = np.load(speaker_embeddings[key])
39
-
40
- # randomly shuffle the elements
41
- np.random.shuffle(speaker_embedding)
42
-
43
- # randomly flip half the values
44
- x = (np.random.rand(512) >= 0.5) * 1.0
45
- x[x == 0] = -1.0
46
- speaker_embedding *= x
47
-
48
- #speaker_embedding = np.random.rand(512).astype(np.float32) * 0.3 - 0.15
49
- else:
50
- speaker_embedding = np.load(speaker_embeddings[speaker[:3]])
51
 
52
  speaker_embedding = torch.tensor(speaker_embedding).unsqueeze(0)
53
 
@@ -91,12 +75,10 @@ article = """
91
  """
92
 
93
  examples = [
94
- ["It is not in the stars to hold our destiny but in ourselves.", "BDL (male)"],
95
- ["The octopus and Oliver went to the opera in October.", "CLB (female)"],
96
- ["She sells seashells by the seashore. I saw a kitten eating chicken in the kitchen.", "RMS (male)"],
97
- ["Brisk brave brigadiers brandished broad bright blades, blunderbusses, and bludgeons—balancing them badly.", "SLT (female)"],
98
- ["A synonym for cinnamon is a cinnamon synonym.", "BDL (male)"],
99
- ["How much wood would a woodchuck chuck if a woodchuck could chuck wood? He would chuck, he would, as much as he could, and chuck as much wood as a woodchuck would if a woodchuck could chuck wood.", "CLB (female)"],
100
  ]
101
 
102
  gr.Interface(
@@ -104,14 +86,10 @@ gr.Interface(
104
  inputs=[
105
  gr.Text(label="Input Text"),
106
  gr.Radio(label="Speaker", choices=[
107
- "BDL (male)",
108
  "CLB (female)",
109
- "KSP (male)",
110
- "RMS (male)",
111
- "SLT (female)",
112
- "Surprise Me!"
113
  ],
114
- value="BDL (male)"),
115
  ],
116
  outputs=[
117
  gr.Audio(label="Generated Speech", type="numpy"),
 
6
  from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan
7
 
8
 
9
+ checkpoint = "GreenCounsel/speecht5_tts_common_voice_5_sv"
10
  processor = SpeechT5Processor.from_pretrained(checkpoint)
11
  model = SpeechT5ForTextToSpeech.from_pretrained(checkpoint)
12
  vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
 
31
  input_ids = inputs["input_ids"]
32
  input_ids = input_ids[..., :model.config.max_text_positions]
33
 
34
+ speaker_embedding = np.load(speaker_embeddings[speaker[:3]])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  speaker_embedding = torch.tensor(speaker_embedding).unsqueeze(0)
37
 
 
75
  """
76
 
77
  examples = [
78
+ ["GreenCounsel grundades i Malmö för sex år sedan.", "CLB (female)"],
79
+ ["Med hjälp av maskininlärning kan mycket av juridiken automatiseras samtidigt som juristerna fokuserar på frågor där de ger störst värde.GreenCounsel har byggt en chatbott som kan förstå frågor på många olika språk och ge kvalitetssäkrade svar.She sells seashells by the seashore. I saw a kitten eating chicken in the kitchen.", "CLB (female)"],
80
+ ["GreenCounsel har byggt en chatbott som kan förstå frågor många olika språk och ge kvalitetssäkrade svar.", "CLB (female)"],
81
+ ["Vi har också byggt ett system för att automatisera arbetsflöden för juridiska tjänster via internet.", "CLB (female)"],
 
 
82
  ]
83
 
84
  gr.Interface(
 
86
  inputs=[
87
  gr.Text(label="Input Text"),
88
  gr.Radio(label="Speaker", choices=[
 
89
  "CLB (female)",
90
+
 
 
 
91
  ],
92
+ value="CLB (female)"),
93
  ],
94
  outputs=[
95
  gr.Audio(label="Generated Speech", type="numpy"),