Hi please somehow allow my script to detect if it's being run inside wsl and if it…
- User
Hi please somehow allow my script to detect if it's being run inside wsl and if it detects that it is then set up the file paths for wsl like because I'm trying to set an output path on my windows path in my program but its getting confused maybe because im doing this in both wsl and windows either way fix the entire script and return it please import os from fastapi import FastAPI, HTTPException, UploadFile, File, Form from fastapi.responses import FileResponse import torch from huggingface_hub import snapshot_download from tempfile import NamedTemporaryFile from typing import Optional import uvicorn
from models.vc.vevo.vevo_utils import VevoInferencePipeline, save_audio # Make sure this path is correct
app = FastAPI(title="Vevo TTS API")
===== Device =====
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
Download and initialize model pipeline once
print("Downloading model checkpoints and initializing the inference pipeline...")
local_dir_tokenizer = snapshot_download( repo_id="amphion/Vevo", repo_type="model", cache_dir="./ckpts/Vevo", allow_patterns=["tokenizer/vq8192/*"], ) content_style_tokenizer_ckpt_path = os.path.join(local_dir_tokenizer, "tokenizer/vq8192")
local_dir_ar = snapshot_download( repo_id="amphion/Vevo", repo_type="model", cache_dir="./ckpts/Vevo", allow_patterns=["contentstyle_modeling/PhoneToVq8192/*"], ) ar_cfg_path = "./models/vc/vevo/config/PhoneToVq8192.json" ar_ckpt_path = os.path.join(local_dir_ar, "contentstyle_modeling/PhoneToVq8192")
local_dir_fmt = snapshot_download( repo_id="amphion/Vevo", repo_type="model", cache_dir="./ckpts/Vevo", allow_patterns=["acoustic_modeling/Vq8192ToMels/*"], ) fmt_cfg_path = "./models/vc/vevo/config/Vq8192ToMels.json" fmt_ckpt_path = os.path.join(local_dir_fmt, "acoustic_modeling/Vq8192ToMels")
local_dir_vocoder = snapshot_download( repo_id="amphion/Vevo", repo_type="model", cache_dir="./ckpts/Vevo", allow_patterns=["acoustic_modeling/Vocoder/*"], ) vocoder_cfg_path = "./models/vc/vevo/config/Vocoder.json" vocoder_ckpt_path = os.path.join(local_dir_vocoder, "acoustic_modeling/Vocoder")
inference_pipeline = VevoInferencePipeline( content_style_tokenizer_ckpt_path=content_style_tokenizer_ckpt_path, ar_cfg_path=ar_cfg_path, ar_ckpt_path=ar_ckpt_path, fmt_cfg_path=fmt_cfg_path, fmt_ckpt_path=fmt_ckpt_path, vocoder_cfg_path=vocoder_cfg_path, vocoder_ckpt_path=vocoder_ckpt_path, device=device, )
print("Model loaded and ready.")
@app.post("/vevo_tts/") async def vevo_tts_endpoint( src_text: str = Form(...), ref_text: Optional[str] = Form(None), src_language: str = Form("en"), ref_language: str = Form("en"), style_ref_wav: UploadFile = File(...), timbre_ref_wav: Optional[UploadFile] = File(None), ): try: # Save uploaded style_ref_wav to a temporary file with NamedTemporaryFile(suffix=os.path.splitext(style_ref_wav.filename)[-1], delete=False) as style_tmp: style_tmp.write(await style_ref_wav.read()) style_ref_path = style_tmp.name
- Assistant