Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,35 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
-
from TTS.api import TTS
|
| 4 |
import torch
|
| 5 |
-
import spaces
|
| 6 |
|
| 7 |
-
#
|
| 8 |
os.environ["COQUI_TOS_AGREED"] = "1"
|
| 9 |
|
| 10 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
|
|
|
|
|
|
| 12 |
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
|
| 13 |
|
| 14 |
-
|
|
|
|
| 15 |
def clone_voice(text, language, speaker_audio):
|
|
|
|
|
|
|
|
|
|
| 16 |
output_path = "output.wav"
|
|
|
|
|
|
|
| 17 |
tts.tts_to_file(
|
| 18 |
text=text,
|
| 19 |
file_path=output_path,
|
|
@@ -22,13 +38,18 @@ def clone_voice(text, language, speaker_audio):
|
|
| 22 |
)
|
| 23 |
return output_path
|
| 24 |
|
|
|
|
| 25 |
iface = gr.Interface(
|
| 26 |
fn=clone_voice,
|
| 27 |
inputs=[
|
| 28 |
-
gr.Textbox(label="Text", value="Namaste,
|
| 29 |
gr.Dropdown(label="Language", choices=["hi", "en"], value="hi"),
|
| 30 |
-
gr.Audio(label="
|
| 31 |
],
|
| 32 |
-
outputs=gr.Audio(label="
|
|
|
|
|
|
|
| 33 |
)
|
| 34 |
-
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
import torch
|
| 4 |
+
import spaces # ZeroGPU Magic
|
| 5 |
|
| 6 |
+
# 1. Terms Accept
|
| 7 |
os.environ["COQUI_TOS_AGREED"] = "1"
|
| 8 |
|
| 9 |
+
# 2. Model Installation Check
|
| 10 |
+
print("⏳ Importing TTS...")
|
| 11 |
+
try:
|
| 12 |
+
from TTS.api import TTS
|
| 13 |
+
except ImportError:
|
| 14 |
+
print("❌ TTS Install Failed. Check requirements.txt")
|
| 15 |
+
raise
|
| 16 |
+
|
| 17 |
+
# 3. Load Model (GPU Support)
|
| 18 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 19 |
+
print(f"⚙️ Device Selected: {device}")
|
| 20 |
+
|
| 21 |
+
# Model ko global variable mein rakhenge
|
| 22 |
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
|
| 23 |
|
| 24 |
+
# 4. Voice Cloning Function (With ZeroGPU Decorator)
|
| 25 |
+
@spaces.GPU(duration=120)
|
| 26 |
def clone_voice(text, language, speaker_audio):
|
| 27 |
+
if not text or not speaker_audio:
|
| 28 |
+
return None
|
| 29 |
+
|
| 30 |
output_path = "output.wav"
|
| 31 |
+
|
| 32 |
+
# Generate Audio
|
| 33 |
tts.tts_to_file(
|
| 34 |
text=text,
|
| 35 |
file_path=output_path,
|
|
|
|
| 38 |
)
|
| 39 |
return output_path
|
| 40 |
|
| 41 |
+
# 5. UI Setup
|
| 42 |
iface = gr.Interface(
|
| 43 |
fn=clone_voice,
|
| 44 |
inputs=[
|
| 45 |
+
gr.Textbox(label="Text to Speak", value="Namaste, ye meri cloned aawaz hai.", lines=2),
|
| 46 |
gr.Dropdown(label="Language", choices=["hi", "en"], value="hi"),
|
| 47 |
+
gr.Audio(label="Upload Speaker Voice (WAV/MP3)", type="filepath")
|
| 48 |
],
|
| 49 |
+
outputs=gr.Audio(label="Generated Audio"),
|
| 50 |
+
title="🚀 Shubham's Super Fast XTTS (H200 GPU)",
|
| 51 |
+
description="ZeroGPU powered Hindi Voice Cloning."
|
| 52 |
)
|
| 53 |
+
|
| 54 |
+
if __name__ == "__main__":
|
| 55 |
+
iface.launch()
|