File size: 1,696 Bytes
2bd30ac
 
d828ce4
2bd30ac
 
d828ce4
b18273d
2bd30ac
2f91434
 
 
 
 
d828ce4
b18273d
925480a
b18273d
 
 
925480a
b18273d
925480a
 
b18273d
925480a
2bd30ac
d828ce4
 
2bd30ac
 
d828ce4
925480a
5de8cee
 
2bd30ac
70865a3
 
 
 
 
 
6bb3a38
d828ce4
5de8cee
 
 
b18273d
d828ce4
5de8cee
 
d828ce4
5de8cee
 
d828ce4
 
082c85f
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
# Use Python 3.10 as base image for better compatibility with ML libraries
FROM python:3.10-slim

# Set working directory
WORKDIR /app

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

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

# Set environment variables
ENV TRANSFORMERS_CACHE=/app/.cache/huggingface/hub
ENV HF_HOME=/app/.cache/huggingface
ENV GIT_CONFIG_GLOBAL=/app/.git/config

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

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

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

# Download model using litgpt command line with proper secret mounting
RUN --mount=type=secret,id=HF_TOKEN,mode=0444,required=true \
    export HF_TOKEN=$(cat /run/secrets/HF_TOKEN) && \
    echo "Starting model download..." && \
    litgpt download mistralai/Mistral-7B-Instruct-v0.3 \
        --access_token ${HF_TOKEN} \
        --checkpoint_dir /app/main/checkpoints || { echo "Download failed with status $?"; exit 1; }

# Copy the rest of the application
COPY . .

# Set environment variables for the application
ENV LLM_ENGINE_HOST=0.0.0.0
ENV LLM_ENGINE_PORT=7860
ENV MODEL_PATH=/app/main/checkpoints/mistralai/Mistral-7B-Instruct-v0.3

# Expose port 7860 for Hugging Face Spaces
EXPOSE 7860

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