Team Ai
Apppublic

PrayingBird/llm-code-deployment-api

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
Dockerfile62 linesDownload Raw Back to root
1# --------------------------------------------------------------------------------2# Stage 1: Base Image and System Setup3# Use a Python slim image for a smaller final container size.4# Replace with nvidia/cuda-xx.x-cudnn-x-runtime if you require GPU access.5FROM python:3.10-slim6 7# Set up the application port. Hugging Face Spaces defaults to 7860.8# Ensure this matches the 'app_port' value in your README.md if you change it.9ARG APP_PORT=786010ENV PORT=${APP_PORT}11 12# Install necessary system dependencies (e.g., C/C++ compilers for libraries like llama-cpp-python)13# If you are using a pure PyTorch/Transformer model, you can skip the build dependencies.14# If you run a model like Llama 3.2 via llama_cpp_python, these are essential.15USER root16RUN apt-get update && \17    apt-get install -y --no-install-recommends \18    gcc \19    g++ \20    cmake \21    git \22    && apt-get clean && \23    rm -rf /var/lib/apt/lists/*24    25# --------------------------------------------------------------------------------26# Stage 2: User Setup and Environment Security27# Create a non-root user for security best practice on Hugging Face Spaces.28RUN useradd -m -u 1000 user29USER user30 31# Set environment variables for the user32ENV HOME=/home/user33ENV PATH="${HOME}/.local/bin:${PATH}"34 35# Set the working directory for the application36WORKDIR /app37 38# --------------------------------------------------------------------------------39# Stage 3: Python Dependencies and Model Loading40# Copy requirements.txt first to leverage Docker layer caching41COPY --chown=user requirements.txt .42 43# Install dependencies using --no-cache-dir for faster builds and smaller layers44# You may need to add --extra-index-url if using custom package repositories45RUN pip install --no-cache-dir -r requirements.txt46 47# If you are downloading a large model, this is where you would do it.48# E.g., via huggingface_hub or cloning a repo.49 50# --------------------------------------------------------------------------------51# Stage 4: Application Code and Startup52# Copy the application code (FastAPI/Flask app) and necessary files53# --chown=user ensures the non-root user owns these files.54COPY --chown=user . .55 56# Expose the application port (matching the ENV PORT above and the README.md)57EXPOSE ${APP_PORT}58 59# Define the command to run the application (assuming your entry file is main.py)60# This example uses Uvicorn to run a FastAPI app named 'app' in main.py.61# Replace 'main:app' with 'your_file_name:app' if your entry file is different.62CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]