Spaces:
Running on Zero
Running on Zero
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -15,6 +15,25 @@ import os
|
|
| 15 |
|
| 16 |
import gradio as gr
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
from voicetut_tts import VoiceTutTTS, GenerationParams
|
| 19 |
from voicetut_tts.engine import DEFAULT_REPO
|
| 20 |
|
|
@@ -163,6 +182,7 @@ def _lang_code(language):
|
|
| 163 |
return "en" if "English" in (language or "") else "arz"
|
| 164 |
|
| 165 |
|
|
|
|
| 166 |
def gen_builtin(speaker_name, text, language, num_step, guidance, speed, normalize):
|
| 167 |
if not text or not text.strip():
|
| 168 |
raise gr.Error("اكتب النص الأول من فضلك")
|
|
@@ -173,6 +193,7 @@ def gen_builtin(speaker_name, text, language, num_step, guidance, speed, normali
|
|
| 173 |
return (TTS.sampling_rate, wav)
|
| 174 |
|
| 175 |
|
|
|
|
| 176 |
def gen_clone(ref_audio, ref_text, text, language, num_step, guidance, speed, normalize):
|
| 177 |
if not text or not text.strip():
|
| 178 |
raise gr.Error("اكتب النص الأول")
|
|
@@ -224,8 +245,9 @@ def _chunk_to_wav_bytes(sr, wav):
|
|
| 224 |
return buf.getvalue()
|
| 225 |
|
| 226 |
|
|
|
|
| 227 |
def stream_tts(text, speaker_name, ref_audio, ref_text, language,
|
| 228 |
-
num_step, guidance, speed, normalize,
|
| 229 |
"""Stream long text sentence-by-sentence: yields (audio_chunk, metrics_html)."""
|
| 230 |
import time
|
| 231 |
if not text or not text.strip():
|
|
|
|
| 15 |
|
| 16 |
import gradio as gr
|
| 17 |
|
| 18 |
+
# HuggingFace ZeroGPU support: GPU is allocated per-request inside @spaces.GPU functions.
|
| 19 |
+
# Guarded so the app still runs locally / on a dedicated GPU without the `spaces` package.
|
| 20 |
+
try:
|
| 21 |
+
import spaces
|
| 22 |
+
_ZEROGPU = True
|
| 23 |
+
except ImportError:
|
| 24 |
+
_ZEROGPU = False
|
| 25 |
+
|
| 26 |
+
class _NoSpaces: # no-op decorator fallback
|
| 27 |
+
@staticmethod
|
| 28 |
+
def GPU(*dargs, **dkwargs):
|
| 29 |
+
def deco(fn):
|
| 30 |
+
return fn
|
| 31 |
+
# support both @spaces.GPU and @spaces.GPU(duration=...)
|
| 32 |
+
if len(dargs) == 1 and callable(dargs[0]) and not dkwargs:
|
| 33 |
+
return dargs[0]
|
| 34 |
+
return deco
|
| 35 |
+
spaces = _NoSpaces()
|
| 36 |
+
|
| 37 |
from voicetut_tts import VoiceTutTTS, GenerationParams
|
| 38 |
from voicetut_tts.engine import DEFAULT_REPO
|
| 39 |
|
|
|
|
| 182 |
return "en" if "English" in (language or "") else "arz"
|
| 183 |
|
| 184 |
|
| 185 |
+
@spaces.GPU(duration=120)
|
| 186 |
def gen_builtin(speaker_name, text, language, num_step, guidance, speed, normalize):
|
| 187 |
if not text or not text.strip():
|
| 188 |
raise gr.Error("اكتب النص الأول من فضلك")
|
|
|
|
| 193 |
return (TTS.sampling_rate, wav)
|
| 194 |
|
| 195 |
|
| 196 |
+
@spaces.GPU(duration=120)
|
| 197 |
def gen_clone(ref_audio, ref_text, text, language, num_step, guidance, speed, normalize):
|
| 198 |
if not text or not text.strip():
|
| 199 |
raise gr.Error("اكتب النص الأول")
|
|
|
|
| 245 |
return buf.getvalue()
|
| 246 |
|
| 247 |
|
| 248 |
+
@spaces.GPU(duration=180)
|
| 249 |
def stream_tts(text, speaker_name, ref_audio, ref_text, language,
|
| 250 |
+
num_step, guidance, speed, normalize, use_clone=False):
|
| 251 |
"""Stream long text sentence-by-sentence: yields (audio_chunk, metrics_html)."""
|
| 252 |
import time
|
| 253 |
if not text or not text.strip():
|