Abhaykoul commited on
Commit
53bc3ba
1 Parent(s): bd691a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +99 -28
app.py CHANGED
@@ -1,35 +1,106 @@
1
- import spaces
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
- device = "cuda"
 
9
 
10
- tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
 
 
11
 
12
- @spaces.GPU(enable_queue=True)
13
  def clone(text, audio):
14
- tts.tts_to_file(text=text, speaker_wav=audio, language="en", file_path="./output.wav")
15
- return "./output.wav"
16
-
17
- iface = gr.Interface(fn=clone,
18
- inputs=[gr.Textbox(label='Text'),gr.Audio(type='filepath', label='Voice reference audio file')],
19
- outputs=gr.Audio(type='filepath'),
20
- title='Voice Clone',
21
- description="""
22
- by [Tony Assi](https://www.tonyassi.com/)
23
-
24
- This space uses xtts_v2 model. Non-commercial use only. [Coqui Public Model License](https://coqui.ai/cpml)
25
-
26
- Please ❤️ this Space. <a href="mailto: tony.assi.media@gmail.com">Email me</a>.
27
- """,
28
- theme = gr.themes.Base(primary_hue="teal",secondary_hue="teal",neutral_hue="slate"),
29
- examples=[["Hey! It's me Dorthy, from the Wizard of Oz. Type in whatever you'd like me to say.","./audio/Wizard-of-Oz-Dorthy.wav"],
30
- ["It's me Vito Corleone, from the Godfather. Type in whatever you'd like me to say.","./audio/Godfather.wav"],
31
- ["Hey, it's me Paris Hilton. Type in whatever you'd like me to say.","./audio/Paris-Hilton.mp3"],
32
- ["Hey, it's me Megan Fox from Transformers. Type in whatever you'd like me to say.","./audio/Megan-Fox.mp3"],
33
- ["Hey there, it's me Jeff Goldblum. Type in whatever you'd like me to say.","./audio/Jeff-Goldblum.mp3"],
34
- ["Hey there, it's me Heath Ledger as the Joker. Type in whatever you'd like me to say.","./audio/Heath-Ledger.mp3"],])
35
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)