FROM pytorch/pytorch:2.9.1-cuda12.8-cudnn9-runtime

ARG HEARTLIB_COMMIT=3783bdb8441f2c298b1e64c8651173aac200361c

RUN apt-get update \
    && apt-get install -y --no-install-recommends git ffmpeg curl \
    && rm -rf /var/lib/apt/lists/*

RUN git clone https://github.com/HeartMuLa/heartlib.git /opt/heartlib \
    && git -C /opt/heartlib checkout "${HEARTLIB_COMMIT}" \
    && pip install --no-cache-dir -e /opt/heartlib \
    && pip install --no-cache-dir gradio==5.49.1 uvicorn==0.35.0

COPY app.py /opt/app/app.py

WORKDIR /opt/app
ENV PYTHONUNBUFFERED=1 \
    HEARTMULA_MODEL_PATH=/models/ckpt \
    HEARTMULA_OUTPUT_DIR=/output

EXPOSE 7860
CMD ["python", "/opt/app/app.py"]
