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

        if timbre_ref_wav is None:
            timbre_ref_wav_path = style_ref_path
        else:
            with NamedTemporaryFile(suffix=os.path.splitext(timbre_ref_wav.filename)[-1], delete=False) as timbre_tmp:
                timbre_tmp.write(await timbre_ref_wav.read())
                timbre_ref_wav_path = timbre_tmp.name

        # Temporary file for output audio
        with NamedTemporaryFile(suffix=".wav", delete=False) as output_tmp:
            output_path = output_tmp.name

        # Run inference
        gen_audio = inference_pipeline.inference_ar_and_fm(
            src_wav_path=None,
            src_text=src_text,
            style_ref_wav_path=style_ref_path,
            timbre_ref_wav_path=timbre_ref_wav_path,
            style_ref_wav_text=ref_text,
            src_text_language=src_language,
            style_ref_wav_text_language=ref_language,
        )

        save_audio(gen_audio, output_path=output_path)

        # Cleanup input temp files
        os.unlink(style_ref_path)
        if timbre_ref_wav is not None:
            os.unlink(timbre_ref_wav_path)

        # Send output wav file
        return FileResponse(output_path, media_type="audio/wav", filename="output.wav")

    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))


if __name__ == "__main__":
    # Run Uvicorn programmatically with reload disabled for actual deployments
    uvicorn.run(app, host="0.0.0.0", port=8000)