FROM python:3.9-slim

# Install necessary system packages
RUN apt-get update && apt-get install -y \
    git \
    gcc g++ \
    ffmpeg \
    fontconfig \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Set up working directory
WORKDIR /app

# Clone the repository
RUN git clone https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI.git . 

# Install Python dependencies
RUN pip install --upgrade pip==23.1 \
    && pip install librosa==0.9.2 numba==0.55.2 llvmlite==0.38.0 \
    && pip install -r requirements.txt

# Adjust permissions for /app and its subdirectories
RUN chmod -R 777 /app

# Ensure Matplotlib and Fontconfig have writable cache directories
RUN mkdir -p /tmp/matplotlib /tmp/fontconfig /app/TEMP && chmod -R 777 /tmp /app/TEMP
ENV MPLCONFIGDIR=/tmp/matplotlib
ENV FONTCONFIG_PATH=/tmp/fontconfig

# Environment variables for numba
ENV NUMBA_CACHE_DIR=/tmp/numba_cache
ENV NUMBA_DISABLE_JIT=1

# Run the application
CMD ["python", "infer-web.py"]