Percy3822 commited on
Commit
ac493b7
·
verified ·
1 Parent(s): 7378896

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -6
app.py CHANGED
@@ -17,16 +17,38 @@ from fastapi.responses import JSONResponse, FileResponse, PlainTextResponse
17
  from fastapi.middleware.cors import CORSMiddleware
18
 
19
  # --------------------------
20
- # CONFIG & PATHS
21
  # --------------------------
22
- BASE_DIR = pathlib.Path(os.environ.get("TTS_BASE_DIR", "/tmp/tts_app")).resolve()
23
- FILES_DIR = BASE_DIR / "files"
24
- VOICES_DIR = BASE_DIR / "voices" # Writable! We populate models here.
25
- PIPER_BIN = shutil.which("piper") or "/usr/local/bin/piper"
 
 
 
 
 
 
 
 
 
 
 
26
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  FILES_DIR.mkdir(parents=True, exist_ok=True)
28
  VOICES_DIR.mkdir(parents=True, exist_ok=True)
29
-
30
  # Known, reliable Piper model URLs (tiny selections). You can add more later.
31
  # These are Rhasspy / Piper HF mirror direct archives that contain .onnx + .onnx.json.
32
  KNOWN_VOICES = {
 
17
  from fastapi.middleware.cors import CORSMiddleware
18
 
19
  # --------------------------
20
+ # CONFIG & PATHS (robust writable base)
21
  # --------------------------
22
+ import os, pathlib, tempfile
23
+
24
+ def _first_writable(candidates):
25
+ for p in candidates:
26
+ try:
27
+ path = pathlib.Path(p).resolve()
28
+ path.mkdir(parents=True, exist_ok=True)
29
+ # sanity: try to create a tiny temp inside
30
+ (path / ".write_test").write_text("ok", encoding="utf-8")
31
+ (path / ".write_test").unlink(missing_ok=True)
32
+ return path
33
+ except Exception:
34
+ continue
35
+ # last resort: use Python's temp dir
36
+ return pathlib.Path(tempfile.gettempdir()).resolve() / "tts_app"
37
 
38
+ # allow override via env var, else try common writable roots in HF Spaces
39
+ _env_base = os.environ.get("TTS_BASE_DIR", "").strip()
40
+ _candidates = []
41
+ if _env_base:
42
+ _candidates.append(_env_base)
43
+ _candidates += ["/data/tts_app", "/tmp/tts_app", "/home/user/tts_app"]
44
+
45
+ BASE_DIR = _first_writable(_candidates)
46
+ BASE_DIR.mkdir(parents=True, exist_ok=True)
47
+
48
+ FILES_DIR = BASE_DIR / "files"
49
+ VOICES_DIR = BASE_DIR / "voices"
50
  FILES_DIR.mkdir(parents=True, exist_ok=True)
51
  VOICES_DIR.mkdir(parents=True, exist_ok=True)
 
52
  # Known, reliable Piper model URLs (tiny selections). You can add more later.
53
  # These are Rhasspy / Piper HF mirror direct archives that contain .onnx + .onnx.json.
54
  KNOWN_VOICES = {