Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,44 @@ import datetime
|
|
| 2 |
from pathlib import Path
|
| 3 |
import gradio as gr
|
| 4 |
import random
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
from style_bert_vits2.constants import (
|
| 6 |
DEFAULT_LENGTH,
|
| 7 |
DEFAULT_LINE_SPLIT,
|
|
@@ -250,4 +288,4 @@ if __name__ == "__main__":
|
|
| 250 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 251 |
model_holder = TTSModelHolder(Path("model_assets"), device)
|
| 252 |
app = create_inference_app(model_holder)
|
| 253 |
-
app.launch(inbrowser=True)
|
|
|
|
| 2 |
from pathlib import Path
|
| 3 |
import gradio as gr
|
| 4 |
import random
|
| 5 |
+
import os
|
| 6 |
+
import shutil
|
| 7 |
+
from huggingface_hub import snapshot_download
|
| 8 |
+
|
| 9 |
+
# --- LOGIKA AUTO-DOWNLOAD BERT (Hanya Folder BERT) ---
|
| 10 |
+
def download_bert_assets():
|
| 11 |
+
print("Checking for BERT assets...")
|
| 12 |
+
REPO_ID = "Plana-Archive/Plana-TTS"
|
| 13 |
+
SOURCE_SUBFOLDER = "sbv2-chupa-demo/bert"
|
| 14 |
+
# Target folder di root Space harus bernama 'bert'
|
| 15 |
+
DEST_FOLDER = "./bert"
|
| 16 |
+
|
| 17 |
+
if not os.path.exists(DEST_FOLDER):
|
| 18 |
+
try:
|
| 19 |
+
print(f"Downloading BERT assets from {REPO_ID}...")
|
| 20 |
+
# Mengunduh folder bert ke folder sementara
|
| 21 |
+
temp_dir = snapshot_download(
|
| 22 |
+
repo_id=REPO_ID,
|
| 23 |
+
allow_patterns=[f"{SOURCE_SUBFOLDER}/**/*"],
|
| 24 |
+
token=os.getenv("HF_TOKEN")
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
# Memindahkan isi dari folder hasil download ke root/bert
|
| 28 |
+
src_path = os.path.join(temp_dir, SOURCE_SUBFOLDER)
|
| 29 |
+
if os.path.exists(src_path):
|
| 30 |
+
shutil.copytree(src_path, DEST_FOLDER)
|
| 31 |
+
print("✅ BERT assets downloaded and linked successfully.")
|
| 32 |
+
else:
|
| 33 |
+
print("⚠️ BERT path not found in downloaded snapshot.")
|
| 34 |
+
except Exception as e:
|
| 35 |
+
print(f"❌ Failed to download BERT: {e}")
|
| 36 |
+
else:
|
| 37 |
+
print("✅ BERT assets already exist.")
|
| 38 |
+
|
| 39 |
+
# Jalankan download sebelum import model
|
| 40 |
+
download_bert_assets()
|
| 41 |
+
|
| 42 |
+
# --- LANJUT KE LOGIKA ASLI APP.PY ---
|
| 43 |
from style_bert_vits2.constants import (
|
| 44 |
DEFAULT_LENGTH,
|
| 45 |
DEFAULT_LINE_SPLIT,
|
|
|
|
| 288 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 289 |
model_holder = TTSModelHolder(Path("model_assets"), device)
|
| 290 |
app = create_inference_app(model_holder)
|
| 291 |
+
app.launch(inbrowser=True)
|