#FROM pytorch/pytorch:2.0.1-cuda11.7-cudnn8-runtime as build
FROM pytorch/pytorch:1.10.0-cuda11.3-cudnn8-runtime as build

RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential python3-venv && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

RUN python3 -m venv /opt/myenv
ENV PATH="/opt/myenv/bin:$PATH"

WORKDIR /app
COPY . /app

RUN pip install --no-cache-dir Flask && \
    pip install --no-cache-dir matplotlib && \
    pip install --no-cache-dir scikit-learn && \
    pip install --no-cache-dir transformers && \
    pip install --no-cache-dir pandas && \
    pip install --no-cache-dir sentence_transformers && \
    pip install --no-cache-dir --upgrade setuptools wheel

RUN rm -rf /root/.cache/pip


FROM pytorch/pytorch:1.10.0-cuda11.3-cudnn8-runtime
COPY --from=build /opt/myenv /opt/myenv

ENV PATH="/opt/myenv/bin:$PATH"

WORKDIR /app
COPY . /app

RUN chown -R www-data:www-data /app && chmod -R 755 /app

EXPOSE 5000

CMD ["/opt/myenv/bin/python", "/app/api.py"]
