""" Austrian Dialect Text-to-Speech Interface for Hugging Face Spaces Based on FastSpeech 2 with dialect embeddings Models are downloaded from a private Hugging Face model repository at startup. Set the Space variable FastSpeechHifiGANckpt to your repo ID (e.g. username/repo-name). """ import gradio as gr import os import spaces from huggingface_hub import hf_hub_download from InferenceInterfaces.InferenceFastSpeech2 import InferenceFastSpeech2 # --------------------------------------------------------------------------- # Model repo configuration # The Space variable "FastSpeechHifiGANckpt" holds the repo ID. # Fallback to env var, then to a placeholder so the app can still import. # --------------------------------------------------------------------------- MODEL_REPO_ID = os.getenv("FastSpeechHifiGANckpt", os.getenv("MODEL_REPO_ID", "")) MODEL_DIR = os.path.expanduser("~/.cache/austrian_tts_models") os.makedirs(MODEL_DIR, exist_ok=True) os.makedirs("audios", exist_ok=True) # Files to download from the model repo and where they need to end up # so that InferenceFastSpeech2 can find them under MODEL_DIR. MODEL_FILES = { # repo filename -> local path relative to MODEL_DIR "best.pt": "FastSpeech2_Austrian_vox107_wav2vec_espeak/best.pt", "best_HiFiGAN.pt": "HiFiGAN_aridialect/best.pt", } def download_models(): """Download model checkpoints from HF Hub and lay out the Models/ tree.""" if not MODEL_REPO_ID: raise RuntimeError( "No model repo ID found. Set the Space variable " "FastSpeechHifiGANckpt or the MODEL_REPO_ID env var." ) os.makedirs(os.path.join(MODEL_DIR, "FastSpeech2_Austrian_vox107_wav2vec_espeak"), exist_ok=True) os.makedirs(os.path.join(MODEL_DIR, "HiFiGAN_aridialect"), exist_ok=True) for repo_file, local_rel in MODEL_FILES.items(): target = os.path.join(MODEL_DIR, local_rel) if os.path.exists(target): print(f"Already cached: {target}") continue print(f"Downloading {repo_file} from {MODEL_REPO_ID} ...") cached = hf_hub_download( repo_id=MODEL_REPO_ID, filename=repo_file, repo_type="model", token=os.environ["TTS_access_model"], ) os.symlink(cached, target) print(f" -> {target}") print("All models ready.") # --------------------------------------------------------------------------- # UI constants (identical to set_up_interface_tab_lang.py) # --------------------------------------------------------------------------- HEADER = ( '