File size: 1,776 Bytes
bf340fa
9f6ffb8
 
 
 
 
 
 
5eea850
 
 
83dc8bf
 
 
bf340fa
9f6ffb8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bf340fa
 
9f6ffb8
bf340fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9f6ffb8
 
 
bf340fa
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
# Hugging Face Spaces Docker SDK Image
FROM python:3.11-slim

# Set environment variables
ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    PORT=7860 \
    HOST=0.0.0.0 \
    ENABLE_PROMPT_GUARD=false \
    OMP_NUM_THREADS=1 \
    MKL_NUM_THREADS=1 \
    DATA_DIR=/app/knowledge_base \
    INDEX_DIR=/app/knowledge_base/indexes \
    PROCESSED_DIR=/app/knowledge_base/processed \
    HF_HOME=/app/.cache/huggingface

WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    curl \
    git \
    ffmpeg \
    libsndfile1 \
    && rm -rf /var/lib/apt/lists/*

# Copy requirements and install python packages
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r requirements.txt

# Pre-cache embedding model weights into Docker image at build time
RUN python -c "from transformers import AutoTokenizer, AutoModel; AutoTokenizer.from_pretrained('intfloat/multilingual-e5-small'); AutoModel.from_pretrained('intfloat/multilingual-e5-small')"

# Copy application source code and pre-built index/processed artifacts
COPY config.py .
COPY main.py .
COPY knowledge_base/ ./knowledge_base/
COPY doc_chunking/ ./doc_chunking/
COPY vector_search/ ./vector_search/
COPY voice_stt/ ./voice_stt/
COPY safety_guardrails/ ./safety_guardrails/
COPY llm_synthesis/ ./llm_synthesis/
COPY rag_pipeline/ ./rag_pipeline/
COPY api_endpoints/ ./api_endpoints/
COPY latency_benchmarks/ ./latency_benchmarks/
COPY web_ui/ ./web_ui/

# Create user for Hugging Face Spaces security
RUN useradd -m -u 1000 user && \
    chown -R user:user /app
USER user

# Expose default Hugging Face Spaces port
EXPOSE 7860

# Launch FastAPI server
CMD ["python", "main.py"]