Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,106 @@
|
|
| 1 |
-
import
|
| 2 |
import gradio as gr
|
| 3 |
import torch
|
| 4 |
from TTS.api import TTS
|
| 5 |
-
import os
|
| 6 |
-
os.environ["COQUI_TOS_AGREED"] = "1"
|
| 7 |
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
@spaces.GPU(enable_queue=True)
|
| 13 |
def clone(text, audio):
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
import gradio as gr
|
| 3 |
import torch
|
| 4 |
from TTS.api import TTS
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
# Agree to Coqui TOS
|
| 7 |
+
os.environ["COQUI_TOS_AGREED"] = "1"
|
| 8 |
|
| 9 |
+
# Initialize TTS model
|
| 10 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 11 |
+
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2", device=device)
|
| 12 |
|
|
|
|
| 13 |
def clone(text, audio):
|
| 14 |
+
output_path = "./output.wav"
|
| 15 |
+
tts.tts_to_file(text=text, speaker_wav=audio, language="en", file_path=output_path)
|
| 16 |
+
return output_path
|
| 17 |
+
|
| 18 |
+
# Define the UI using Blocks
|
| 19 |
+
with gr.Blocks(title="Advanced Voice Clone", theme=gr.themes.Soft(primary_hue="teal")) as demo:
|
| 20 |
+
gr.Markdown(
|
| 21 |
+
"""
|
| 22 |
+
# 🎤 Voice Clone
|
| 23 |
+
|
| 24 |
+
**by [Tony Assi](https://www.tonyassi.com/)**
|
| 25 |
+
|
| 26 |
+
This application uses the **xtts_v2** model for voice cloning.
|
| 27 |
+
*Non-commercial use only.*
|
| 28 |
+
|
| 29 |
+
[Coqui Public Model License](https://coqui.ai/cpml) |
|
| 30 |
+
📧 [Contact Me](mailto:tony.assi.media@gmail.com)
|
| 31 |
+
|
| 32 |
+
---
|
| 33 |
+
"""
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
with gr.Row():
|
| 37 |
+
with gr.Column(scale=1):
|
| 38 |
+
text_input = gr.Textbox(
|
| 39 |
+
label="Enter Text",
|
| 40 |
+
placeholder="Type the text you want to clone...",
|
| 41 |
+
lines=4
|
| 42 |
+
)
|
| 43 |
+
audio_input = gr.Audio(
|
| 44 |
+
type="filepath",
|
| 45 |
+
label="Upload Reference Voice",
|
| 46 |
+
elem_id="audio_upload"
|
| 47 |
+
)
|
| 48 |
+
clone_button = gr.Button("Clone Voice", variant="primary")
|
| 49 |
+
|
| 50 |
+
with gr.Column(scale=1):
|
| 51 |
+
output_audio = gr.Audio(
|
| 52 |
+
type="filepath",
|
| 53 |
+
label="Cloned Voice Output",
|
| 54 |
+
interactive=False
|
| 55 |
+
)
|
| 56 |
+
with gr.Accordion("Example Voices", open=False):
|
| 57 |
+
gr.Markdown(
|
| 58 |
+
"""
|
| 59 |
+
### Preloaded Examples
|
| 60 |
+
|
| 61 |
+
- **Dorothy from Wizard of Oz**
|
| 62 |
+
- *Sample Audio:* [Download](./audio/Wizard-of-Oz-Dorthy.wav)
|
| 63 |
+
- **Vito Corleone from The Godfather**
|
| 64 |
+
- *Sample Audio:* [Download](./audio/Godfather.wav)
|
| 65 |
+
- **Paris Hilton**
|
| 66 |
+
- *Sample Audio:* [Download](./audio/Paris-Hilton.mp3)
|
| 67 |
+
- **Megan Fox from Transformers**
|
| 68 |
+
- *Sample Audio:* [Download](./audio/Megan-Fox.mp3)
|
| 69 |
+
- **Jeff Goldblum**
|
| 70 |
+
- *Sample Audio:* [Download](./audio/Jeff-Goldblum.mp3)
|
| 71 |
+
- **Heath Ledger as the Joker**
|
| 72 |
+
- *Sample Audio:* [Download](./audio/Heath-Ledger.mp3)
|
| 73 |
+
"""
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
gr.Markdown(
|
| 77 |
+
"""
|
| 78 |
+
---
|
| 79 |
+
❤️ If you find this tool useful, please consider giving it a thumbs up!
|
| 80 |
+
"""
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
# Connect the button to the function
|
| 84 |
+
clone_button.click(
|
| 85 |
+
clone,
|
| 86 |
+
inputs=[text_input, audio_input],
|
| 87 |
+
outputs=output_audio,
|
| 88 |
+
queue=True
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
+
# Add custom CSS for enhanced styling
|
| 92 |
+
demo.add_css("""
|
| 93 |
+
#audio_upload > label {
|
| 94 |
+
background-color: #14b8a6;
|
| 95 |
+
color: white;
|
| 96 |
+
padding: 10px;
|
| 97 |
+
border-radius: 5px;
|
| 98 |
+
cursor: pointer;
|
| 99 |
+
}
|
| 100 |
+
#audio_upload > label:hover {
|
| 101 |
+
background-color: #0d9488;
|
| 102 |
+
}
|
| 103 |
+
""")
|
| 104 |
+
|
| 105 |
+
# Launch the app
|
| 106 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|