SmolDocling-256M-Demo/Dockerfile

44 lines
1.3 KiB
Docker

# Use the official Python image as the base image.
FROM python:3.10-slim
# Declare build argument with a default value (0 means GPU not enabled)
ARG ENABLE_CUDA=0
# Set environment variables to optimize Python behavior in the container.
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV ENABLE_CUDA=1
# Set the working directory inside the container.
WORKDIR /app
# Install system dependencies.
RUN apt-get update && \
apt-get install -y --no-install-recommends \
build-essential \
curl \
libmagic1 \
&& rm -rf /var/lib/apt/lists/*
# Copy the requirements file.
COPY requirements.txt .
# Conditionally install dependencies:
# - If ENABLE_CUDA=1, install all dependencies.
# - Otherwise, filter out GPU-specific dependencies.
RUN pip install --upgrade pip && \
if [ "$ENABLE_CUDA" -eq "1" ]; then \
pip install --no-cache-dir -r requirements.txt; \
else \
grep -v 'llama_index.readers.docling' requirements.txt > requirements_filtered.txt && \
pip install --no-cache-dir -r requirements_filtered.txt; \
fi
# Copy the entire project directory into the container.
COPY . .
# Expose the port on which FastAPI will run.
EXPOSE 7860
# Define the default command to run the FastAPI application using uvicorn.
CMD ["python", "app.py"]