#!/bin/bash
MODEL_NAME="Wan2.1-T2V-14B"

# Create ubuntu directory
mkdir -p /home/ubuntu
cd /home/ubuntu

# Clone repo
git clone https://github.com/Wan-Video/Wan2.1.git
cd Wan2.1

# Install uv (for super fast pip install)
export HOME=/home/ubuntu
sudo curl -LsSf https://astral.sh/uv/install.sh | sh
source $HOME/.local/bin/env

# Create virtual environment with python 3.11
uv venv --python 3.11
source .venv/bin/activate

# Install dependencies
uv pip install setuptools
uv pip install torch
uv pip install nvitop # to monitor GPU usage
uv pip install -r requirements.txt --no-build-isolation

# Download model
sudo chown -R ubuntu:ubuntu /ephemeral/
uv pip install "huggingface_hub[cli]"
huggingface-cli download Wan-AI/$MODEL_NAME --local-dir /ephemeral/$MODEL_NAME

# Set model directory for Huggingface
export HF_HOME=/ephemeral/huggingface

# Fix permissions
sudo chown -R ubuntu:ubuntu /home/ubuntu

# Deploy gradio (defaults to port 7860)
cd gradio

python t2v_14B_singleGPU.py --prompt_extend_method 'local_qwen' --prompt_extend_model 'Qwen/Qwen2.5-7B-Instruct' --ckpt_dir /ephemeral/$MODEL_NAME

