File size: 2,169 Bytes
a33458e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
403ced7
8faa239
 
 
403ced7
 
8faa239
403ced7
8faa239
 
a33458e
 
 
9f0d171
 
 
 
 
 
a33458e
403ced7
 
a33458e
8faa239
 
31cd25b
 
403ced7
 
 
207d24c
403ced7
31cd25b
a33458e
403ced7
 
 
 
 
 
9f0d171
 
 
 
 
 
403ced7
780b542
a33458e
403ced7
9f0d171
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
63
64
65
66
67
FROM python:3.10-slim

WORKDIR /app

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

# Copy requirements first for better caching
COPY requirements.txt .

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

# Create all cache directories with proper permissions
RUN mkdir -p /.cache && chmod 777 /.cache
RUN mkdir -p /root/.cache && chmod 777 /root/.cache
RUN mkdir -p /app/.cache && chmod 777 /app/.cache
RUN mkdir -p /tmp/.cache && chmod 777 /tmp/.cache
RUN mkdir -p /home/.cache && chmod 777 /home/.cache

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

# Copy the rest of the application
COPY . .

# Create necessary directories with proper permissions and unique vector_db folders
RUN mkdir -p data/documents && chmod -R 777 data/documents
RUN mkdir -p data/vector_db && chmod -R 777 data/vector_db
# Create multiple vector_db instances to avoid collisions
RUN mkdir -p data/vector_db_1 data/vector_db_2 data/vector_db_3 && \
    chmod -R 777 data/vector_db_*

# Set environment variables for cache locations
ENV TRANSFORMERS_CACHE=/app/models
ENV TOKENIZERS_PARALLELISM=false
ENV HF_HOME=/app/.cache
ENV XDG_CACHE_HOME=/app/.cache
ENV HUGGINGFACEHUB_API_TOKEN=""
ENV HF_API_KEY=""

# Use small local models that don't require API access
# distilgpt2 is a small model that works well locally
ENV LLM_MODEL="distilgpt2"
# all-MiniLM-L6-v2 is small and efficient for embeddings
ENV EMBEDDING_MODEL="sentence-transformers/all-MiniLM-L6-v2"

# Set moderate temperature and token limit
ENV DEFAULT_TEMPERATURE=0.7
ENV MAX_TOKENS=256
ENV CHUNK_SIZE=512
ENV CHUNK_OVERLAP=128

# Set server.maxMessageSize for Streamlit to handle large uploads
ENV STREAMLIT_SERVER_MAX_MESSAGE_SIZE=200

# Set shared memory settings to improve performance
ENV PYTHONHASHSEED=0

# Expose port for Hugging Face Spaces
EXPOSE 7860

# Run the Streamlit app on the correct port
CMD ["streamlit", "run", "app/ui/streamlit_app.py", "--server.port=7860", "--server.address=0.0.0.0", "--server.maxUploadSize=10"]