write me a unity script for an android app that connects to this server (running on my PC) I want all changeable values in the inspector of the script and I want a public button press action for generate song and I want the output to automatically be played through the phone when it gets it.

import os
import sys
import asyncio
import uuid
import threading
from typing import List, Optional

# Must be set very early before loading OpenMP runtime-dependent modules
os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE"

from fastapi import FastAPI, HTTPException, Request
from fastapi.staticfiles import StaticFiles
from pydantic import BaseModel
from acestep.pipeline_ace_step import ACEStepPipeline
from contextlib import asynccontextmanager
import uvicorn
from concurrent.futures import ThreadPoolExecutor

# Constants & config
SHUTDOWN_AUTH_TOKEN = "your-secret-token"  # Change to a secure key
AUDIO_OUTPUT_DIR = os.path.join(os.getcwd(), "generated_audio")

# Ensure output directory exists
os.makedirs(AUDIO_OUTPUT_DIR, exist_ok=True)

PRELOAD_CONFIG = {
    "checkpoint_path": "",
    "bf16": True,
    "torch_compile": False,
    "device_id": 0,
}

# Globals
preloaded_pipeline: Optional[ACEStepPipeline] = None
pipeline_lock: Optional[asyncio.Lock] = None
server: Optional[uvicorn.Server] = None
thread_pool: Optional[ThreadPoolExecutor] = ThreadPoolExecutor(max_workers=4)  # Tune max_workers as needed

class ACEStepInput(BaseModel):
    audio_duration: float
    prompt: str
    lyrics: str
    infer_step: int
    guidance_scale: float
    scheduler_type: str
    cfg_type: str
    omega_scale: float
    actual_seeds: List[int]
    guidance_interval: float
    guidance_interval_decay: float
    min_guidance_scale: float
    use_erg_tag: bool
    use_erg_lyric: bool
    use_erg_diffusion: bool
    oss_steps: List[int]
    guidance_scale_text: float = 0.0
    guidance_scale_lyric: float = 0.0

class ACEStepOutput(BaseModel):
    status: str
    output_path: Optional[str]
    message: str

def set_cuda_device(device_id: int) -> None:
    current_cuda_visible_devices = os.environ.get("CUDA_VISIBLE_DEVICES")
    device_str = str(device_id)
    if current_cuda_visible_devices != device_str:
        os.environ["CUDA_VISIBLE_DEVICES"] = device_str

def initialize_pipeline(
    checkpoint_path: str,
    bf16: bool,
    torch_compile: bool,
    device_id: int,
) -> ACEStepPipeline:
    set_cuda_device(device_id)
    dtype = "bfloat16" if bf16 else "float32"
    pipeline = ACEStepPipeline(
        checkpoint_dir=checkpoint_path,
        dtype=dtype,
        torch_compile=torch_compile,
    )
    return pipeline

async def run_generation_in_thread(pipeline: ACEStepPipeline, params: tuple, output_path: str):
    loop = asyncio.get_running_loop()
    # Use the existing global thread pool for lightweight thread scheduling
    await loop.run_in_executor(thread_pool, lambda: pipeline(*params, save_path=output_path))

@asynccontextmanager
async def lifespan(app: FastAPI):
    global preloaded_pipeline, pipeline_lock
    cfg = PRELOAD_CONFIG
    preloaded_pipeline = initialize_pipeline(
        cfg["checkpoint_path"],
        cfg["bf16"],
        cfg["torch_compile"],
        cfg["device_id"],
    )
    pipeline_lock = asyncio.Lock()
    print("Preloaded model pipeline at startup.")
    yield
    # Cleanup
    preloaded_pipeline = None
    pipeline_lock = None
    # Also cleanup thread pool gracefully
    thread_pool.shutdown(wait=False)
    print("Pipeline cleaned up and thread pool shutdown on server shutdown.")

app = FastAPI(title="ACEStep Pipeline API", lifespan=lifespan)

# Use a dedicated directory for static files to avoid exposing unwanted files
app.mount("/files", StaticFiles(directory=AUDIO_OUTPUT_DIR), name="files")

@app.post("/generate", response_model=ACEStepOutput)
async def generate_audio(input_data: ACEStepInput):
    if preloaded_pipeline is None or pipeline_lock is None:
        raise HTTPException(status_code=503, detail="Model pipeline is not ready")

    # Precompute seeds and oss_steps as strings once
    try:
        actual_seeds_str = ", ".join(map(str, input_data.actual_seeds))
        oss_steps_str = ", ".join(map(str, input_data.oss_steps))

        params = (
            input_data.audio_duration,
            input_data.prompt,
            input_data.lyrics,
            input_data.infer_step,
            input_data.guidance_scale,
            input_data.scheduler_type,
            input_data.cfg_type,
            input_data.omega_scale,
            actual_seeds_str,
            input_data.guidance_interval,
            input_data.guidance_interval_decay,
            input_data.min_guidance_scale,
            input_data.use_erg_tag,
            input_data.use_erg_lyric,
            input_data.use_erg_diffusion,
            oss_steps_str,
            input_data.guidance_scale_text,
            input_data.guidance_scale_lyric,
        )
        # Generate a unique filename
        filename = f"output_{uuid.uuid4().hex}.wav"
        output_path = os.path.join(AUDIO_OUTPUT_DIR, filename)

        async with pipeline_lock:
            # Run blocking generation on thread pool
            await run_generation_in_thread(preloaded_pipeline, params, output_path)

        return ACEStepOutput(
            status="success",
            output_path=f"files/{filename}",  # Paths relative to /files static mount
            message="Audio generated successfully",
        )
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"Error generating audio: {str(e)}")

@app.get("/health")
async def health_check():
    return {"status": "healthy"}

@app.post("/shutdown")
async def shutdown(request: Request):
    """
    Requires X-Auth-Token header with the correct secret token.
    Triggers graceful server shutdown.
    """
    global server
    token = request.headers.get("X-Auth-Token")
    if token != SHUTDOWN_AUTH_TOKEN:
        raise HTTPException(status_code=401, detail="Unauthorized")

    if server is None:
        raise HTTPException(status_code=503, detail="Server instance not found")

    def stop_server():
        print("Shutdown initiated via /shutdown endpoint.")
        server.should_exit = True

    threading.Thread(target=stop_server).start()
    return {"status": "shutting down"}

def run_uvicorn(port: int = 8000):
    global server
    config = uvicorn.Config(
        app,
        host="0.0.0.0",
        port=port,
        log_level="info",
        # You can tune workers if CPU-bound, but check if your pipeline supports multi-gpu or parallel processing
        # workers=2,
    )
    server = uvicorn.Server(config)
    server.run()

if __name__ == "__main__":
    port = 8000
    if "--port" in sys.argv:
        try:
            idx = sys.argv.index("--port")
            if idx + 1 < len(sys.argv):
                port = int(sys.argv[idx + 1])
        except Exception:
            print("Invalid port argument passed; falling back to default port 8000")

    run_uvicorn(port)