FROM python:3.11-slim

ARG DISABLE_VOSK=false

RUN apt-get update && apt-get install -y ffmpeg && rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY requirements-web.txt .
RUN if [ "$DISABLE_VOSK" = "true" ]; then \
        grep -v '^vosk' requirements-web.txt > /tmp/requirements.txt && \
        pip install --no-cache-dir -r /tmp/requirements.txt; \
    else \
        pip install --no-cache-dir -r requirements-web.txt; \
    fi

COPY web_api.py .
COPY Restore_Colorize.json .
COPY Create_Image.json .

RUN mkdir -p /app/output /app/uploads /app/logs /app/models /home/appuser/.cache/huggingface && \
    groupadd -g 1000 appuser && \
    useradd -u 1000 -g appuser -m appuser && \
    chown -R appuser:appuser /app /home/appuser/.cache

USER appuser

EXPOSE 8000

CMD ["python", "web_api.py"]
