Eyob-Sol commited on
Commit
0646466
·
verified ·
1 Parent(s): 5a8b6d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -46
app.py CHANGED
@@ -46,51 +46,12 @@ def ensure_model() -> str:
46
  return model_path
47
 
48
 
49
- # ---------------------------------------
50
- # Piper: rely on the PyPI wheel (piper-tts)
51
- # ---------------------------------------
52
- # --- keep your existing imports ---
53
- import os
54
- from huggingface_hub import hf_hub_download
55
-
56
- def ensure_piper_voice():
57
- """
58
- Make sure the Piper voice model exists at PIPER_MODEL.
59
- Defaults to Amy-medium English if none specified.
60
- """
61
- target_path = os.getenv("PIPER_MODEL", "models/piper/en_US-amy-medium.onnx")
62
- repo_id = os.getenv("PIPER_VOICE_REPO", "rhasspy/piper-voices")
63
- hf_file = os.getenv("PIPER_VOICE_FILE",
64
- "en/en_US/en_US-amy-medium.onnx") # path inside the repo
65
-
66
- # If already present, we're done.
67
- if os.path.exists(target_path):
68
- print(f"[PIPER] Voice model present: {target_path}")
69
- return target_path
70
-
71
- os.makedirs(os.path.dirname(target_path), exist_ok=True)
72
- print(f"[PIPER] Downloading voice {hf_file} from {repo_id} …")
73
- local = hf_hub_download(
74
- repo_id=repo_id,
75
- filename=hf_file,
76
- local_dir=os.path.dirname(target_path),
77
- local_dir_use_symlinks=False,
78
- )
79
- # Move/rename to the exact target filename if the name differs
80
- if os.path.abspath(local) != os.path.abspath(target_path):
81
- import shutil
82
- shutil.copyfile(local, target_path)
83
- print(f"[PIPER] Voice ready at: {target_path}")
84
- return target_path
85
-
86
- # No PIPER_BIN provided → try PATH
87
- resolved = which("piper")
88
- if resolved:
89
- print(f"[PIPER] Found in PATH: {resolved}")
90
- return resolved
91
-
92
- print("[PIPER] Not found. Install via 'piper-tts' wheel in requirements.txt.")
93
- return None
94
 
95
 
96
  def log_env_for_audio():
@@ -112,7 +73,8 @@ def main():
112
  # Ensure model exists locally
113
  ensure_model()
114
 
115
- ensure_piper_voice()
 
116
 
117
  # Launch Gradio
118
  demo = build_demo()
 
46
  return model_path
47
 
48
 
49
+ def _ensure_exec(fp: str):
50
+ if fp and os.path.exists(fp):
51
+ try:
52
+ os.chmod(fp, 0o755)
53
+ except Exception as e:
54
+ print("[WARN] chmod failed for", fp, e)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
 
56
 
57
  def log_env_for_audio():
 
73
  # Ensure model exists locally
74
  ensure_model()
75
 
76
+ # Make sure bundled Piper can run (no downloads on Spaces)
77
+ _ensure_exec(os.getenv("PIPER_BIN", ""))
78
 
79
  # Launch Gradio
80
  demo = build_demo()