Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -7,4 +7,66 @@ st.write(x, 'squared is', x * x)
|
|
7 |
|
8 |
git add app.py
|
9 |
git commit -m "Add application file"
|
10 |
-
git push
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
git add app.py
|
9 |
git commit -m "Add application file"
|
10 |
+
git push
|
11 |
+
|
12 |
+
import gradio as gr
|
13 |
+
import os
|
14 |
+
import shlex
|
15 |
+
import gdown
|
16 |
+
import uuid
|
17 |
+
import torch
|
18 |
+
|
19 |
+
cpu_param = "--cpu" if not torch.cuda.is_available() else ""
|
20 |
+
|
21 |
+
if (not os.path.exists("synpretrained.pt")):
|
22 |
+
gdown.download("https://drive.google.com/u/0/uc?id=1EqFMIbvxffxtjiVrtykroF6_mUh-5Z3s&export=download&confirm=t",
|
23 |
+
"synpretrained.pt", quiet=False)
|
24 |
+
gdown.download("https://drive.google.com/uc?export=download&id=1q8mEGwCkFy23KZsinbuvdKAQLqNKbYf1",
|
25 |
+
"encpretrained.pt", quiet=False)
|
26 |
+
gdown.download("https://drive.google.com/uc?export=download&id=1cf2NO6FtI0jDuy8AV3Xgn6leO6dHjIgu",
|
27 |
+
"vocpretrained.pt", quiet=False)
|
28 |
+
|
29 |
+
|
30 |
+
def inference(audio_path, text, mic_path=None):
|
31 |
+
if mic_path:
|
32 |
+
audio_path = mic_path
|
33 |
+
output_path = f"/tmp/output_{uuid.uuid4()}.wav"
|
34 |
+
os.system(
|
35 |
+
f"python demo_cli.py --no_sound {cpu_param} --audio_path {audio_path} --text {shlex.quote(text.strip())} --output_path {output_path}")
|
36 |
+
return output_path
|
37 |
+
|
38 |
+
|
39 |
+
title = "Real-Time-Voice-Cloning"
|
40 |
+
description = "Gradio demo for Real-Time-Voice-Cloning: Clone a voice in 5 seconds to generate arbitrary speech in real-time. To use it, simply upload your audio, or click one of the examples to load them. Read more at the links below."
|
41 |
+
article = "<p style='text-align: center'><a href='https://matheo.uliege.be/handle/2268.2/6801' target='_blank'>Real-Time Voice Cloning</a> | <a href='https://github.com/CorentinJ/Real-Time-Voice-Cloning' target='_blank'>Github Repo</a></p>"
|
42 |
+
|
43 |
+
examples = [['test.wav', "This is real time voice cloning on huggingface spaces"]]
|
44 |
+
|
45 |
+
|
46 |
+
def toggle(choice):
|
47 |
+
if choice == "mic":
|
48 |
+
return gr.update(visible=True, value=None), gr.update(visible=False, value=None)
|
49 |
+
else:
|
50 |
+
return gr.update(visible=False, value=None), gr.update(visible=True, value=None)
|
51 |
+
|
52 |
+
|
53 |
+
with gr.Blocks() as demo:
|
54 |
+
with gr.Row():
|
55 |
+
with gr.Column():
|
56 |
+
radio = gr.Radio(["mic", "file"], value="mic",
|
57 |
+
label="How would you like to upload your audio?")
|
58 |
+
mic_input = gr.Mic(label="Input", type="filepath", visible=False)
|
59 |
+
audio_file = gr.Audio(
|
60 |
+
type="filepath", label="Input", visible=True)
|
61 |
+
text_input = gr.Textbox(label="Text")
|
62 |
+
with gr.Column():
|
63 |
+
audio_output = gr.Audio(label="Output")
|
64 |
+
|
65 |
+
gr.Examples(examples, fn=inference, inputs=[audio_file, text_input],
|
66 |
+
outputs=audio_output, cache_examples=True)
|
67 |
+
btn = gr.Button("Generate")
|
68 |
+
btn.click(inference, inputs=[audio_file,
|
69 |
+
text_input, mic_input], outputs=audio_output)
|
70 |
+
radio.change(toggle, radio, [mic_input, audio_file])
|
71 |
+
|
72 |
+
demo.launch(enable_queue=True)
|