Update app.py
Browse files
app.py
CHANGED
|
@@ -1,47 +1,13 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import tempfile
|
| 3 |
import gradio as gr
|
| 4 |
-
from TTS.api import TTS
|
| 5 |
-
|
| 6 |
-
print("🔁 Loading XTTS model once...")
|
| 7 |
-
|
| 8 |
-
# Accept Coqui license automatically
|
| 9 |
-
os.environ["COQUI_TOS_AGREED"] = "1"
|
| 10 |
-
|
| 11 |
-
tts = TTS(
|
| 12 |
-
model_path="/models/xtts/",
|
| 13 |
-
config_path="/models/xtts/config.json",
|
| 14 |
-
gpu=False
|
| 15 |
-
)
|
| 16 |
-
|
| 17 |
-
print("✅ Model loaded!")
|
| 18 |
-
|
| 19 |
-
def synthesize(text, speaker_wav):
|
| 20 |
-
if not text or speaker_wav is None:
|
| 21 |
-
raise gr.Error("Please provide both text and speaker WAV.")
|
| 22 |
-
|
| 23 |
-
out_path = os.path.join(tempfile.gettempdir(), "out.wav")
|
| 24 |
-
|
| 25 |
-
tts.tts_to_file(
|
| 26 |
-
text=text,
|
| 27 |
-
speaker_wav=speaker_wav,
|
| 28 |
-
language="en",
|
| 29 |
-
file_path=out_path
|
| 30 |
-
)
|
| 31 |
-
|
| 32 |
-
return out_path
|
| 33 |
|
|
|
|
|
|
|
| 34 |
|
| 35 |
demo = gr.Interface(
|
| 36 |
-
fn=
|
| 37 |
-
inputs=
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
],
|
| 41 |
-
outputs=gr.Audio(label="Generated Voice", type="filepath"),
|
| 42 |
-
title="XTTS Voice Cloning API (Offline, HF Space)",
|
| 43 |
-
description="Upload 5–10 seconds clean voice sample + enter text.",
|
| 44 |
-
api_name="tts" # ✅ THIS FIXES 'No API found'
|
| 45 |
)
|
| 46 |
|
| 47 |
demo.queue()
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
def test_api(text):
|
| 4 |
+
return f"You sent: {text}"
|
| 5 |
|
| 6 |
demo = gr.Interface(
|
| 7 |
+
fn=test_api,
|
| 8 |
+
inputs=gr.Textbox(label="Text"),
|
| 9 |
+
outputs=gr.Textbox(label="Output"),
|
| 10 |
+
api_name="test"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
)
|
| 12 |
|
| 13 |
demo.queue()
|