Spaces:
Sleeping
Sleeping
Yarik
commited on
Commit
·
065c08d
1
Parent(s):
66108fb
update 2 app.py
Browse files- app.py +10 -6
- requirements.txt +2 -1
app.py
CHANGED
@@ -20,15 +20,19 @@ from accentor import accentification, stress_replace_and_shift
|
|
20 |
|
21 |
app = FastAPI(docs_url=None, redoc_url=None)
|
22 |
|
23 |
-
# Set environment variable for Hugging Face cache directory
|
24 |
os.environ["HF_HOME"] = "/app/.cache"
|
25 |
-
|
26 |
os.environ["STANZA_RESOURCES_DIR"] = "/app/stanza_resources"
|
27 |
os.environ["MODEL_DIR"] = "/app/model"
|
28 |
|
29 |
# Create necessary directories if they don't exist
|
30 |
-
os.makedirs("
|
31 |
-
os.makedirs("
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
tts_kwargs = {
|
34 |
"speaker_name": "uk",
|
@@ -97,7 +101,7 @@ def trim_memory():
|
|
97 |
|
98 |
def init_models():
|
99 |
models = {}
|
100 |
-
model_path = hf_hub_download("theodotus/tts-vits-lada-uk", "model.pt", cache_dir="
|
101 |
importer = package.PackageImporter(model_path)
|
102 |
models["lada"] = importer.load_pickle("tts_models", "model")
|
103 |
return models
|
@@ -111,7 +115,7 @@ async def tts(request: str, api_data: Auth = Depends(check_api_token)):
|
|
111 |
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as wav_fp:
|
112 |
with no_grad():
|
113 |
wav_data = synt.tts(plussed_text, **tts_kwargs)
|
114 |
-
synt.save_wav(wav_data, wav_fp)
|
115 |
|
116 |
threading.Thread(target=delete_file_after_delay, args=(wav_fp.name, 300)).start()
|
117 |
return JSONResponse(content={"audio_url": f"https://pro100sata-xche-audio.hf.space/download_audio?audio_path={wav_fp.name}"})
|
|
|
20 |
|
21 |
app = FastAPI(docs_url=None, redoc_url=None)
|
22 |
|
23 |
+
# Set environment variable for Hugging Face cache directory and Stanza resources directory
|
24 |
os.environ["HF_HOME"] = "/app/.cache"
|
|
|
25 |
os.environ["STANZA_RESOURCES_DIR"] = "/app/stanza_resources"
|
26 |
os.environ["MODEL_DIR"] = "/app/model"
|
27 |
|
28 |
# Create necessary directories if they don't exist
|
29 |
+
os.makedirs(os.environ["STANZA_RESOURCES_DIR"], exist_ok=True)
|
30 |
+
os.makedirs(os.environ["MODEL_DIR"], exist_ok=True)
|
31 |
+
|
32 |
+
# Download the Ukrainian models for Stanza
|
33 |
+
import stanza
|
34 |
+
|
35 |
+
stanza.download('uk', model_dir=os.environ["STANZA_RESOURCES_DIR"])
|
36 |
|
37 |
tts_kwargs = {
|
38 |
"speaker_name": "uk",
|
|
|
101 |
|
102 |
def init_models():
|
103 |
models = {}
|
104 |
+
model_path = hf_hub_download("theodotus/tts-vits-lada-uk", "model.pt", cache_dir=os.environ["MODEL_DIR"])
|
105 |
importer = package.PackageImporter(model_path)
|
106 |
models["lada"] = importer.load_pickle("tts_models", "model")
|
107 |
return models
|
|
|
115 |
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as wav_fp:
|
116 |
with no_grad():
|
117 |
wav_data = synt.tts(plussed_text, **tts_kwargs)
|
118 |
+
synt.save_wav(wav_data, wav_fp.name)
|
119 |
|
120 |
threading.Thread(target=delete_file_after_delay, args=(wav_fp.name, 300)).start()
|
121 |
return JSONResponse(content={"audio_url": f"https://pro100sata-xche-audio.hf.space/download_audio?audio_path={wav_fp.name}"})
|
requirements.txt
CHANGED
@@ -8,4 +8,5 @@ uvicorn
|
|
8 |
pydub
|
9 |
passlib
|
10 |
ctranslate2
|
11 |
-
sentencepiece
|
|
|
|
8 |
pydub
|
9 |
passlib
|
10 |
ctranslate2
|
11 |
+
sentencepiece
|
12 |
+
stanza
|