[Admin maintenance] Migrate grant to ZeroGPU
Browse files
app.py
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
|
|
| 1 |
import torch
|
| 2 |
torch.manual_seed(160923)
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
import gradio as gr
|
| 6 |
import torch.cuda
|
|
@@ -24,14 +35,38 @@ class TTSWebUI:
|
|
| 24 |
path_to_iso_list = hf_hub_download(repo_id="Flux9665/ToucanTTS", filename="iso_to_fullname.json")
|
| 25 |
iso_to_name = load_json_from_path(path_to_iso_list)
|
| 26 |
text_selection = [f"{iso_to_name[iso_code]} ({iso_code})" for iso_code in iso_to_name]
|
| 27 |
-
# accent_selection = [f"{iso_to_name[iso_code]} Accent ({iso_code})" for iso_code in iso_to_name]
|
| 28 |
|
| 29 |
self.controllable_ui = ControllableInterface(gpu_id=gpu_id,
|
| 30 |
available_artificial_voices=available_artificial_voices,
|
| 31 |
tts_model_path=tts_model_path,
|
| 32 |
vocoder_model_path=vocoder_model_path,
|
| 33 |
embedding_gan_path=embedding_gan_path)
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
inputs=[gr.Textbox(lines=2,
|
| 36 |
placeholder="write what you want the synthesis to read here...",
|
| 37 |
value="What I cannot create, I do not understand.",
|
|
@@ -45,9 +80,6 @@ class TTSWebUI:
|
|
| 45 |
gr.Slider(minimum=0, maximum=available_artificial_voices, step=1, value=5, label="Random Seed for the artificial Voice"),
|
| 46 |
gr.Slider(minimum=-10.0, maximum=10.0, step=0.1, value=0.0, label="Gender of artificial Voice"),
|
| 47 |
gr.Audio(type="filepath", show_label=True, container=True, label="[OPTIONAL] Voice to Clone (if left empty, will use an artificial voice instead)"),
|
| 48 |
-
# gr.Slider(minimum=0.5, maximum=1.5, step=0.1, value=1.0, label="Pitch Variance Scale"),
|
| 49 |
-
# gr.Slider(minimum=0.5, maximum=1.5, step=0.1, value=1.0, label="Energy Variance Scale"),
|
| 50 |
-
# gr.Slider(minimum=-10.0, maximum=10.0, step=0.1, value=0.0, label="Voice Depth")
|
| 51 |
],
|
| 52 |
outputs=[gr.Audio(type="numpy", label="Speech"),
|
| 53 |
gr.Image(label="Visualization")],
|
|
@@ -57,37 +89,6 @@ class TTSWebUI:
|
|
| 57 |
theme=gr.themes.Ocean(primary_hue="amber", secondary_hue="orange"))
|
| 58 |
self.iface.launch()
|
| 59 |
|
| 60 |
-
def read(self,
|
| 61 |
-
prompt,
|
| 62 |
-
language,
|
| 63 |
-
prosody_creativity,
|
| 64 |
-
duration_scaling_factor,
|
| 65 |
-
voice_seed,
|
| 66 |
-
emb1,
|
| 67 |
-
reference_audio,
|
| 68 |
-
# pitch_variance_scale,
|
| 69 |
-
# energy_variance_scale,
|
| 70 |
-
# emb2
|
| 71 |
-
):
|
| 72 |
-
sr, wav, fig = self.controllable_ui.read(prompt,
|
| 73 |
-
reference_audio,
|
| 74 |
-
language.split(" ")[-1].split("(")[1].split(")")[0],
|
| 75 |
-
language.split(" ")[-1].split("(")[1].split(")")[0],
|
| 76 |
-
voice_seed,
|
| 77 |
-
prosody_creativity,
|
| 78 |
-
duration_scaling_factor,
|
| 79 |
-
1.,
|
| 80 |
-
1.0,
|
| 81 |
-
1.0,
|
| 82 |
-
emb1,
|
| 83 |
-
0.,
|
| 84 |
-
0.,
|
| 85 |
-
0.,
|
| 86 |
-
0.,
|
| 87 |
-
0.,
|
| 88 |
-
-24.)
|
| 89 |
-
return (sr, float2pcm(wav)), fig
|
| 90 |
-
|
| 91 |
|
| 92 |
if __name__ == '__main__':
|
| 93 |
TTSWebUI(gpu_id="cuda" if torch.cuda.is_available() else "cpu")
|
|
|
|
| 1 |
+
import spaces
|
| 2 |
import torch
|
| 3 |
torch.manual_seed(160923)
|
| 4 |
|
| 5 |
+
_orig_set_device = torch.cuda.set_device
|
| 6 |
+
def _safe_set_device(device):
|
| 7 |
+
try:
|
| 8 |
+
_orig_set_device(device)
|
| 9 |
+
except RuntimeError as exc:
|
| 10 |
+
if "Low-level CUDA init" in str(exc):
|
| 11 |
+
return
|
| 12 |
+
raise
|
| 13 |
+
torch.cuda.set_device = _safe_set_device
|
| 14 |
+
|
| 15 |
|
| 16 |
import gradio as gr
|
| 17 |
import torch.cuda
|
|
|
|
| 35 |
path_to_iso_list = hf_hub_download(repo_id="Flux9665/ToucanTTS", filename="iso_to_fullname.json")
|
| 36 |
iso_to_name = load_json_from_path(path_to_iso_list)
|
| 37 |
text_selection = [f"{iso_to_name[iso_code]} ({iso_code})" for iso_code in iso_to_name]
|
|
|
|
| 38 |
|
| 39 |
self.controllable_ui = ControllableInterface(gpu_id=gpu_id,
|
| 40 |
available_artificial_voices=available_artificial_voices,
|
| 41 |
tts_model_path=tts_model_path,
|
| 42 |
vocoder_model_path=vocoder_model_path,
|
| 43 |
embedding_gan_path=embedding_gan_path)
|
| 44 |
+
|
| 45 |
+
controllable_ui = self.controllable_ui
|
| 46 |
+
|
| 47 |
+
@spaces.GPU
|
| 48 |
+
def read(prompt, language, prosody_creativity, duration_scaling_factor, voice_seed, emb1, reference_audio):
|
| 49 |
+
iso = language.split(" ")[-1].split("(")[1].split(")")[0]
|
| 50 |
+
sr, wav, fig = controllable_ui.read(prompt,
|
| 51 |
+
reference_audio,
|
| 52 |
+
iso,
|
| 53 |
+
iso,
|
| 54 |
+
voice_seed,
|
| 55 |
+
prosody_creativity,
|
| 56 |
+
duration_scaling_factor,
|
| 57 |
+
1.,
|
| 58 |
+
1.0,
|
| 59 |
+
1.0,
|
| 60 |
+
emb1,
|
| 61 |
+
0.,
|
| 62 |
+
0.,
|
| 63 |
+
0.,
|
| 64 |
+
0.,
|
| 65 |
+
0.,
|
| 66 |
+
-24.)
|
| 67 |
+
return (sr, float2pcm(wav)), fig
|
| 68 |
+
|
| 69 |
+
self.iface = gr.Interface(fn=read,
|
| 70 |
inputs=[gr.Textbox(lines=2,
|
| 71 |
placeholder="write what you want the synthesis to read here...",
|
| 72 |
value="What I cannot create, I do not understand.",
|
|
|
|
| 80 |
gr.Slider(minimum=0, maximum=available_artificial_voices, step=1, value=5, label="Random Seed for the artificial Voice"),
|
| 81 |
gr.Slider(minimum=-10.0, maximum=10.0, step=0.1, value=0.0, label="Gender of artificial Voice"),
|
| 82 |
gr.Audio(type="filepath", show_label=True, container=True, label="[OPTIONAL] Voice to Clone (if left empty, will use an artificial voice instead)"),
|
|
|
|
|
|
|
|
|
|
| 83 |
],
|
| 84 |
outputs=[gr.Audio(type="numpy", label="Speech"),
|
| 85 |
gr.Image(label="Visualization")],
|
|
|
|
| 89 |
theme=gr.themes.Ocean(primary_hue="amber", secondary_hue="orange"))
|
| 90 |
self.iface.launch()
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
if __name__ == '__main__':
|
| 94 |
TTSWebUI(gpu_id="cuda" if torch.cuda.is_available() else "cpu")
|