CoolFace
Apppublic

23F2003213/llm-code-deployment

sourceHugging Facemitupdated 11mo agoView on Hugging Face
0likes
Dockerfile62 linesDownload Raw Back to root
1# --------------------------------------------------------------------------------
2# Stage 1: Base Image and System Setup
3# 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-slim
6
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=7860
10ENV 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 root
16RUN 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 Security
27# Create a non-root user for security best practice on Hugging Face Spaces.
28RUN useradd -m -u 1000 user
29USER user
30
31# Set environment variables for the user
32ENV HOME=/home/user
33ENV PATH="${HOME}/.local/bin:${PATH}"
34
35# Set the working directory for the application
36WORKDIR /app
37
38# --------------------------------------------------------------------------------
39# Stage 3: Python Dependencies and Model Loading
40# Copy requirements.txt first to leverage Docker layer caching
41COPY --chown=user requirements.txt .
42
43# Install dependencies using --no-cache-dir for faster builds and smaller layers
44# You may need to add --extra-index-url if using custom package repositories
45RUN pip install --no-cache-dir -r requirements.txt
46
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 Startup
52# Copy the application code (FastAPI/Flask app) and necessary files
53# --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"]