ataberkkilavuzcu commited on
Commit
36f8bee
·
1 Parent(s): 80e8047
Files changed (1) hide show
  1. app.py +13 -2
app.py CHANGED
@@ -13,15 +13,26 @@ from pydantic import BaseModel, Field, HttpUrl
13
  from TTS.api import TTS
14
 
15
  SPACE_API_KEY = os.getenv("SPACE_API_KEY")
 
 
 
 
 
 
16
  MAX_TEXT_LENGTH = 1000
17
  DEFAULT_LANGUAGE = "en"
18
 
19
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
20
 
21
  try:
22
- tts_model = TTS("tts_models/multilingual/multi-dataset/xtts_v2", gpu=DEVICE == "cuda")
 
 
23
  except Exception as exc: # pragma: no cover
24
- raise RuntimeError(f"Failed to load XTTS v2 model: {exc}") from exc
 
 
 
25
 
26
  app = FastAPI(title="xtts-v2-api", version="1.0.0")
27
 
 
13
  from TTS.api import TTS
14
 
15
  SPACE_API_KEY = os.getenv("SPACE_API_KEY")
16
+ HF_TOKEN = (
17
+ os.getenv("HUGGING_FACE_HUB_TOKEN")
18
+ or os.getenv("HUGGINGFACEHUB_API_TOKEN")
19
+ or os.getenv("HF_TOKEN")
20
+ )
21
+ MODEL_NAME = "tts_models/multilingual/multi-dataset/xtts_v2"
22
  MAX_TEXT_LENGTH = 1000
23
  DEFAULT_LANGUAGE = "en"
24
 
25
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
26
 
27
  try:
28
+ if HF_TOKEN:
29
+ os.environ.setdefault("HUGGING_FACE_HUB_TOKEN", HF_TOKEN)
30
+ tts_model = TTS(MODEL_NAME, gpu=DEVICE == "cuda", progress_bar=False)
31
  except Exception as exc: # pragma: no cover
32
+ hint = ""
33
+ if "EOF when reading a line" in str(exc):
34
+ hint = " Hint: set HUGGING_FACE_HUB_TOKEN to a Hugging Face token that has accepted the XTTS v2 license."
35
+ raise RuntimeError(f"Failed to load XTTS v2 model: {exc}.{hint}") from exc
36
 
37
  app = FastAPI(title="xtts-v2-api", version="1.0.0")
38