Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import os, re, hmac, threading, traceback
|
| 2 |
from pathlib import Path
|
| 3 |
import numpy as np
|
| 4 |
import torch
|
|
@@ -17,6 +17,7 @@ SECRET = os.environ.get("TTS_SECRET_KEY", "") # khali he to koi key na
|
|
| 17 |
DEFAULT_VOICE = os.environ.get("DEFAULT_VOICE", "") # chahe to default awaaz ka naam yaha daalo
|
| 18 |
MODEL_REPO = "saryps-labs/pocket-tts-hindi"
|
| 19 |
LOCAL_DIR = "/home/user/hindi_model"
|
|
|
|
| 20 |
FALLBACK_VOICE = "hf://kyutai/tts-voices/alba-mackenna/casual.wav"
|
| 21 |
MAX_CHARS = int(os.environ.get("MAX_CHARS", "6000"))
|
| 22 |
GAP_SECONDS = 0.22
|
|
@@ -65,7 +66,7 @@ def get_voice_state(path: str):
|
|
| 65 |
|
| 66 |
|
| 67 |
# ---------------- model ----------------
|
| 68 |
-
def
|
| 69 |
cfg = os.path.join(LOCAL_DIR, "config.yaml")
|
| 70 |
if not os.path.exists(cfg):
|
| 71 |
from huggingface_hub import hf_hub_download
|
|
@@ -82,20 +83,37 @@ def try_load(TTSModel, arg):
|
|
| 82 |
|
| 83 |
def load_everything():
|
| 84 |
global model, SR, state_msg, last_error
|
|
|
|
| 85 |
try:
|
|
|
|
| 86 |
from pocket_tts import TTSModel
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
try:
|
| 92 |
m = try_load(TTSModel, arg)
|
|
|
|
| 93 |
break
|
| 94 |
except Exception as e:
|
| 95 |
-
|
| 96 |
traceback.print_exc()
|
| 97 |
if m is None:
|
| 98 |
-
raise
|
|
|
|
| 99 |
model = m
|
| 100 |
SR = int(getattr(m, "sample_rate", 24000))
|
| 101 |
_, path = resolve_voice(DEFAULT_VOICE)
|
|
@@ -104,7 +122,7 @@ def load_everything():
|
|
| 104 |
print("Pocket TTS Hindi ready, sample rate", SR)
|
| 105 |
except Exception as e:
|
| 106 |
state_msg = "error"
|
| 107 |
-
last_error = f"{type(e).__name__}: {e}"
|
| 108 |
traceback.print_exc()
|
| 109 |
|
| 110 |
|
|
|
|
| 1 |
+
import os, re, hmac, shutil, threading, traceback
|
| 2 |
from pathlib import Path
|
| 3 |
import numpy as np
|
| 4 |
import torch
|
|
|
|
| 17 |
DEFAULT_VOICE = os.environ.get("DEFAULT_VOICE", "") # chahe to default awaaz ka naam yaha daalo
|
| 18 |
MODEL_REPO = "saryps-labs/pocket-tts-hindi"
|
| 19 |
LOCAL_DIR = "/home/user/hindi_model"
|
| 20 |
+
CONFIG_NAME = "hindi_saryps" # library ke config folder me is naam se jayega
|
| 21 |
FALLBACK_VOICE = "hf://kyutai/tts-voices/alba-mackenna/casual.wav"
|
| 22 |
MAX_CHARS = int(os.environ.get("MAX_CHARS", "6000"))
|
| 23 |
GAP_SECONDS = 0.22
|
|
|
|
| 66 |
|
| 67 |
|
| 68 |
# ---------------- model ----------------
|
| 69 |
+
def download_config() -> str:
|
| 70 |
cfg = os.path.join(LOCAL_DIR, "config.yaml")
|
| 71 |
if not os.path.exists(cfg):
|
| 72 |
from huggingface_hub import hf_hub_download
|
|
|
|
| 83 |
|
| 84 |
def load_everything():
|
| 85 |
global model, SR, state_msg, last_error
|
| 86 |
+
errs = []
|
| 87 |
try:
|
| 88 |
+
import pocket_tts
|
| 89 |
from pocket_tts import TTSModel
|
| 90 |
+
|
| 91 |
+
cfg = download_config()
|
| 92 |
+
print("Config file:", cfg)
|
| 93 |
+
|
| 94 |
+
# config ko library ke apne config folder me copy karo, taaki naam se load ho sake
|
| 95 |
+
pkg_cfg_dir = os.path.join(os.path.dirname(pocket_tts.__file__), "config")
|
| 96 |
+
os.makedirs(pkg_cfg_dir, exist_ok=True)
|
| 97 |
+
shutil.copyfile(cfg, os.path.join(pkg_cfg_dir, CONFIG_NAME + ".yaml"))
|
| 98 |
+
print("Config copy hui:", os.path.join(pkg_cfg_dir, CONFIG_NAME + ".yaml"))
|
| 99 |
+
|
| 100 |
+
attempts = [
|
| 101 |
+
("naam se (" + CONFIG_NAME + ")", CONFIG_NAME),
|
| 102 |
+
("Path object", Path(cfg)),
|
| 103 |
+
("bina .yaml ke path", os.path.splitext(cfg)[0]),
|
| 104 |
+
]
|
| 105 |
+
m = None
|
| 106 |
+
for label, arg in attempts:
|
| 107 |
try:
|
| 108 |
m = try_load(TTSModel, arg)
|
| 109 |
+
print("Model load hua:", label)
|
| 110 |
break
|
| 111 |
except Exception as e:
|
| 112 |
+
errs.append(f"[{label}] {type(e).__name__}: {str(e)[:300]}")
|
| 113 |
traceback.print_exc()
|
| 114 |
if m is None:
|
| 115 |
+
raise RuntimeError(" || ".join(errs))
|
| 116 |
+
|
| 117 |
model = m
|
| 118 |
SR = int(getattr(m, "sample_rate", 24000))
|
| 119 |
_, path = resolve_voice(DEFAULT_VOICE)
|
|
|
|
| 122 |
print("Pocket TTS Hindi ready, sample rate", SR)
|
| 123 |
except Exception as e:
|
| 124 |
state_msg = "error"
|
| 125 |
+
last_error = str(e) if errs else f"{type(e).__name__}: {e}"
|
| 126 |
traceback.print_exc()
|
| 127 |
|
| 128 |
|