File size: 1,583 Bytes
5503fad
0f7413f
9d309ad
 
 
 
 
 
 
 
 
5503fad
 
 
9d309ad
 
 
 
 
0f7413f
9d309ad
5503fad
9d309ad
 
 
 
5503fad
 
9d309ad
0f7413f
9d309ad
 
 
b105c47
 
 
 
 
 
 
9d309ad
 
b105c47
9d309ad
 
b105c47
9d309ad
b105c47
 
9d309ad
5503fad
9d309ad
 
5503fad
b105c47
 
 
 
 
9d309ad
0f7413f
5503fad
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
62
# Use NVIDIA CUDA base image with Python support (ONLY for GPU Spaces)
FROM nvidia/cuda:12.1.1-runtime-ubuntu22.04

# Set working directory
WORKDIR /app

# Install Python and system dependencies
RUN apt-get update && apt-get install -y \
    python3.10 \
    python3-pip \
    python3.10-venv \
    python3.10-dev \
    build-essential \
    cmake \
    git \
    curl \
    wget \
    && rm -rf /var/lib/apt/lists/*

# Make python3.10 the default
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.10 1
RUN update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1

# Upgrade pip
RUN pip install --upgrade pip

# Install prebuilt llama-cpp-python CUDA wheel
RUN CMAKE_ARGS="-DLLAMA_CUBLAS=on" pip install --no-cache-dir llama-cpp-python==0.2.90 --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cu121

# Copy requirements.txt and install remaining dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Create a non-root user
RUN useradd -m -u 1000 user

# Create cache directory with proper permissions
RUN mkdir -p /app/.cache/huggingface
RUN chown -R user:user /app

# Copy app code
COPY . .
RUN chown -R user:user /app

# Create models directory
RUN mkdir -p models && chown -R user:user models

# Switch to non-root user
USER user

# Environment variables
ENV GRADIO_SERVER_NAME="0.0.0.0"
ENV GRADIO_SERVER_PORT=7860
ENV CUDA_VISIBLE_DEVICES=0
ENV HF_HOME=/app/.cache/huggingface
ENV TRANSFORMERS_CACHE=/app/.cache/huggingface

# Expose Gradio port
EXPOSE 7860

# Start app
CMD ["python", "app.py"]