File size: 1,783 Bytes
2bd30ac
 
d828ce4
2bd30ac
 
d828ce4
2bd30ac
 
 
 
 
d828ce4
925480a
 
 
 
 
 
 
 
2bd30ac
d828ce4
 
2bd30ac
 
d828ce4
2bd30ac
d828ce4
 
925480a
 
 
2bd30ac
 
 
 
 
a189e20
2bd30ac
 
a189e20
 
 
2bd30ac
a189e20
2bd30ac
d828ce4
 
 
2bd30ac
925480a
 
a189e20
d828ce4
925480a
 
 
 
d828ce4
 
a189e20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Use Python 3.10 as base image for better compatibility with ML libraries
FROM python:3.10-slim

# Set working directory
WORKDIR /app

# Install git and required system dependencies
RUN apt-get update && \
    apt-get install -y git && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# Create cache directory and set permissions
RUN mkdir -p /app/.cache/huggingface && \
    chmod 777 /app/.cache/huggingface

# Set environment variables for cache
ENV TRANSFORMERS_CACHE=/app/.cache/huggingface/hub
ENV HF_HOME=/app/.cache/huggingface

# Copy requirements first to leverage Docker cache
COPY requirements.txt .

# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy the rest of the application
COPY . .

# Create checkpoints directory with proper permissions
RUN mkdir -p /app/checkpoints && \
    chmod 777 /app/checkpoints

# The token will be passed during build time
ARG HF_TOKEN
ENV HF_TOKEN=${HF_TOKEN}

# Download both models using litgpt
# Only proceed if HF_TOKEN is provided
RUN if [ -n "$HF_TOKEN" ]; then \
        python -c "from huggingface_hub import login; from litgpt.cli import download; login('${HF_TOKEN}'); \
        download('meta-llama/Llama-2-3b-chat-hf', '/app/checkpoints'); \
        download('mistralai/Mistral-7B-Instruct-v0.3', '/app/checkpoints')"; \
    else \
        echo "No Hugging Face token provided. Models will need to be downloaded separately."; \
    fi

# Set environment variables
ENV LLM_ENGINE_HOST=0.0.0.0
ENV LLM_ENGINE_PORT=8001

# Update MODEL_PATH for the new model
ENV MODEL_PATH=/app/checkpoints/mistralai/Mistral-7B-Instruct-v0.3

# Expose both ports:
# 8001 for FastAPI
# 7860 for Hugging Face Spaces
EXPOSE 8001 7860

# Command to run the application
CMD ["python", "main/main.py"]