Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,7 @@ if str(APP_ROOT) not in sys.path:
|
|
| 7 |
sys.path.insert(0, str(APP_ROOT))
|
| 8 |
|
| 9 |
import gradio as gr
|
|
|
|
| 10 |
import torch
|
| 11 |
from TTS.api import TTS
|
| 12 |
|
|
@@ -22,6 +23,31 @@ except ImportError:
|
|
| 22 |
"Failed to build monotonic_align extension; ensure build dependencies are installed."
|
| 23 |
) from exc
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
# Get device
|
| 26 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 27 |
|
|
@@ -34,12 +60,17 @@ def voice_clone(text: str, speaker_wav: str, language: str):
|
|
| 34 |
tts.tts_to_file(text=text, speaker_wav=speaker_wav, language=language, file_path="output.wav")
|
| 35 |
return "output.wav"
|
| 36 |
|
| 37 |
-
iface = gr.Interface(
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
iface.launch()
|
|
|
|
| 7 |
sys.path.insert(0, str(APP_ROOT))
|
| 8 |
|
| 9 |
import gradio as gr
|
| 10 |
+
import gradio_client.utils as grc_utils
|
| 11 |
import torch
|
| 12 |
from TTS.api import TTS
|
| 13 |
|
|
|
|
| 23 |
"Failed to build monotonic_align extension; ensure build dependencies are installed."
|
| 24 |
) from exc
|
| 25 |
|
| 26 |
+
# Patch Gradio schema helpers to guard against boolean schemas until upstream fix lands.
|
| 27 |
+
_ORIG_GET_TYPE = getattr(grc_utils, "get_type", None)
|
| 28 |
+
_ORIG_JSON_TO_PY = getattr(grc_utils, "_json_schema_to_python_type", None)
|
| 29 |
+
|
| 30 |
+
def _safe_get_type(schema): # pragma: no cover - runtime patching
|
| 31 |
+
if isinstance(schema, bool):
|
| 32 |
+
return "Any" if schema else "Never"
|
| 33 |
+
if _ORIG_GET_TYPE is None:
|
| 34 |
+
raise AttributeError("gradio_client.utils.get_type is unavailable")
|
| 35 |
+
return _ORIG_GET_TYPE(schema)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def _safe_json_schema_to_python_type(schema, defs=None): # pragma: no cover
|
| 39 |
+
if isinstance(schema, bool):
|
| 40 |
+
return "Any" if schema else "Never"
|
| 41 |
+
if _ORIG_JSON_TO_PY is None:
|
| 42 |
+
raise AttributeError("gradio_client.utils._json_schema_to_python_type is unavailable")
|
| 43 |
+
return _ORIG_JSON_TO_PY(schema, defs)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
if _ORIG_GET_TYPE is not None:
|
| 47 |
+
grc_utils.get_type = _safe_get_type
|
| 48 |
+
if _ORIG_JSON_TO_PY is not None:
|
| 49 |
+
grc_utils._json_schema_to_python_type = _safe_json_schema_to_python_type
|
| 50 |
+
|
| 51 |
# Get device
|
| 52 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 53 |
|
|
|
|
| 60 |
tts.tts_to_file(text=text, speaker_wav=speaker_wav, language=language, file_path="output.wav")
|
| 61 |
return "output.wav"
|
| 62 |
|
| 63 |
+
iface = gr.Interface(
|
| 64 |
+
fn=voice_clone,
|
| 65 |
+
theme="Nymbo/Nymbo_Theme",
|
| 66 |
+
inputs=[
|
| 67 |
+
gr.Textbox(lines=2, placeholder="Enter the text...", label="Text"),
|
| 68 |
+
gr.Audio(type="filepath", label="Upload audio file"),
|
| 69 |
+
gr.Radio(['ru', 'en', 'zh-cn', 'ja', 'de', 'fr', 'it', 'pt', 'pl', 'tr', 'ko', 'nl', 'cs', 'ar', 'es', 'hu'], label="language"),
|
| 70 |
+
],
|
| 71 |
+
outputs=gr.Audio(type="filepath", label="Generated audio file"),
|
| 72 |
+
title="Voice Cloning",
|
| 73 |
+
allow_flagging="never",
|
| 74 |
+
)
|
| 75 |
|
| 76 |
iface.launch()
|