mohammedaly22 commited on
Commit
98d3e11
·
verified ·
1 Parent(s): 7c09955

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +30 -3
app.py CHANGED
@@ -23,6 +23,25 @@ CKPT = os.environ.get("OMNICLEO_CKPT", DEFAULT_REPO)
23
  print(f"Loading VoiceTut-TTS from {CKPT} ...")
24
  TTS = VoiceTutTTS.from_pretrained(CKPT)
25
  SPEAKERS = TTS.list_speakers()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  SPK_BY_NAME = {s.speaker_name: s for s in SPEAKERS}
27
  DEFAULT_SPK = SPEAKERS[0].speaker_name if SPEAKERS else None
28
 
@@ -241,7 +260,8 @@ def preview_reference(speaker_name):
241
  gender = "أنثى ♀" if spk.gender == "female" else "ذكر ♂"
242
  header = (f'<div class="vt-spk-meta"><span class="vt-gender">{gender}</span>'
243
  f'<div class="vt-chips">{chips}</div></div>')
244
- return spk.audio_path, spk.reference_text, header
 
245
 
246
 
247
  # ---------------------------------------------------------------- reusable blocks
@@ -291,7 +311,7 @@ with gr.Blocks(**_blocks_kwargs) as demo:
291
  '<div class="logo">𓋹</div>'
292
  '<div><h1>VoiceTut<span class="accent">-TTS</span></h1>'
293
  '<p>تحويل النص إلى كلام — مصري وإنجليزي · Egyptian Arabic & code-switching TTS</p></div>'
294
- '<div class="badges"><span class="badge">14 صوت</span>'
295
  '<span class="badge">Zero-shot</span><span class="badge">Streaming</span></div>'
296
  '</div>'
297
  )
@@ -382,7 +402,14 @@ with gr.Blocks(**_blocks_kwargs) as demo:
382
 
383
 
384
  if __name__ == "__main__":
385
- allowed = [TTS.registry.base_dir] if TTS.registry else []
 
 
 
 
 
 
 
386
  launch_kwargs = dict(
387
  server_name="0.0.0.0",
388
  server_port=int(os.environ.get("OMNICLEO_PORT", "7860")),
 
23
  print(f"Loading VoiceTut-TTS from {CKPT} ...")
24
  TTS = VoiceTutTTS.from_pretrained(CKPT)
25
  SPEAKERS = TTS.list_speakers()
26
+
27
+ # Copy each speaker's reference WAV into a local dir under the app's CWD.
28
+ # When speakers come from an HF snapshot they live in ~/.cache/huggingface, which Gradio
29
+ # refuses to serve. Mirroring them under ./reference_audio (always inside CWD) avoids the
30
+ # allowed_paths / InvalidPathError problem on HF Spaces and locally alike.
31
+ import shutil
32
+ _REF_DIR = os.path.join(os.getcwd(), "reference_audio")
33
+ os.makedirs(_REF_DIR, exist_ok=True)
34
+ REF_AUDIO = {} # speaker_name -> local servable wav path
35
+ for s in SPEAKERS:
36
+ try:
37
+ dst = os.path.join(_REF_DIR, os.path.basename(s.audio_path))
38
+ if os.path.abspath(s.audio_path) != os.path.abspath(dst):
39
+ shutil.copyfile(s.audio_path, dst)
40
+ REF_AUDIO[s.speaker_name] = dst
41
+ except Exception as e:
42
+ print(f" (warn) couldn't stage reference for {s.speaker_name}: {e}")
43
+ REF_AUDIO[s.speaker_name] = s.audio_path
44
+
45
  SPK_BY_NAME = {s.speaker_name: s for s in SPEAKERS}
46
  DEFAULT_SPK = SPEAKERS[0].speaker_name if SPEAKERS else None
47
 
 
260
  gender = "أنثى ♀" if spk.gender == "female" else "ذكر ♂"
261
  header = (f'<div class="vt-spk-meta"><span class="vt-gender">{gender}</span>'
262
  f'<div class="vt-chips">{chips}</div></div>')
263
+ # use the locally-staged copy so Gradio can serve it (HF snapshot paths are blocked)
264
+ return REF_AUDIO.get(speaker_name, spk.audio_path), spk.reference_text, header
265
 
266
 
267
  # ---------------------------------------------------------------- reusable blocks
 
311
  '<div class="logo">𓋹</div>'
312
  '<div><h1>VoiceTut<span class="accent">-TTS</span></h1>'
313
  '<p>تحويل النص إلى كلام — مصري وإنجليزي · Egyptian Arabic & code-switching TTS</p></div>'
314
+ '<div class="badges"><span class="badge">15 صوت</span>'
315
  '<span class="badge">Zero-shot</span><span class="badge">Streaming</span></div>'
316
  '</div>'
317
  )
 
402
 
403
 
404
  if __name__ == "__main__":
405
+ # Allow serving the staged reference dir, the registry dir, and the HF cache
406
+ # (covers both local checkpoints and HF-snapshot speakers).
407
+ allowed = [_REF_DIR]
408
+ if TTS.registry:
409
+ allowed.append(TTS.registry.base_dir)
410
+ hf_cache = os.path.join(os.path.expanduser("~"), ".cache", "huggingface")
411
+ if os.path.isdir(hf_cache):
412
+ allowed.append(hf_cache)
413
  launch_kwargs = dict(
414
  server_name="0.0.0.0",
415
  server_port=int(os.environ.get("OMNICLEO_PORT", "7860")),