Team Ai
Apppublic

emanism6/Text-Classification-Fastapi

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
0likes
Dockerfile64 linesDownload Raw Back to root
1# syntax=docker/dockerfile:12 3# Base image using the specified Python version4ARG PYTHON_VERSION=3.12.35FROM python:${PYTHON_VERSION}-slim as base6 7# Prevents Python from writing pyc files.8ENV PYTHONDONTWRITEBYTECODE=19 10# Install TensorFlow 2.011RUN pip install tensorflow==2.16.112 13# Install tf-keras package to resolve the missing dependency14RUN pip install tf-keras15 16# Keeps Python from buffering stdout and stderr to avoid situations where17# the application crashes without emitting any logs due to buffering.18ENV PYTHONUNBUFFERED=119 20WORKDIR /app21 22# Create a non-privileged user that the app will run under.23# See https://docs.docker.com/go/dockerfile-user-best-practices/24ARG UID=1000125RUN adduser \26    --disabled-password \27    --gecos "" \28    --home "/nonexistent" \29    --shell "/sbin/nologin" \30    --no-create-home \31    --uid "${UID}" \32    appuser33 34# Download dependencies as a separate step to take advantage of Docker's caching.35# Leverage a cache mount to /root/.cache/pip to speed up subsequent builds.36# Leverage a bind mount to requirements.txt to avoid having to copy them into37# into this layer.38RUN --mount=type=cache,target=/root/.cache/pip \39    --mount=type=bind,source=requirements.txt,target=requirements.txt \40    python -m pip install -r requirements.txt41 42# Switch to the non-privileged user to run the application.43USER appuser44 45# Set the TRANSFORMERS_CACHE environment variable46ENV TRANSFORMERS_CACHE=/tmp/.cache/huggingface47 48# Create the cache folder with appropriate permissions49RUN mkdir -p $TRANSFORMERS_CACHE && chmod -R 777 $TRANSFORMERS_CACHE50 51# Set NLTK data directory52ENV NLTK_DATA=/tmp/nltk_data53 54# Create the NLTK data directory with appropriate permissions55RUN mkdir -p $NLTK_DATA && chmod -R 777 $NLTK_DATA56 57# Copy the source code into the container.58COPY . .59 60# Expose the port that the application listens on.61EXPOSE 786062 63# Run the application.64CMD uvicorn 'main:app' --host=0.0.0.0 --port=7860