File size: 2,475 Bytes
b3b7a20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
FROM python:3.10-slim

WORKDIR /app

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

# Copy configuration files first to optimize Docker cache
COPY pyproject.toml README.md ./

# Upgrade pip and install Python dependencies
RUN pip install --no-cache-dir --upgrade pip
RUN pip install --no-cache-dir -e .

# Check critical imports
RUN python -c "from langchain_qdrant import QdrantVectorStore; print('βœ… Qdrant successfully imported')"
RUN python -c "from fastapi import FastAPI; print('βœ… FastAPI successfully imported')"
RUN python -c "import uvicorn; print('βœ… Uvicorn successfully imported')"

# Create necessary directories with correct permissions
RUN mkdir -p /app/static && \
    mkdir -p /tmp/qdrant_storage && \
    mkdir -p /tmp/cache && \
    chmod -R 777 /tmp/qdrant_storage && \
    chmod -R 777 /tmp/cache

# Copy application files
COPY main.py .
COPY rag_system.py .
COPY agent_workflow.py .
COPY embedding_models.py .
COPY books_config.json .

# Copy the static directory with the interface
COPY static/ ./static/

# Copy the chunks file to the root
COPY all_books_preprocessed_chunks.json .

# Check for the presence of the chunks file at the root
RUN if [ -f "all_books_preprocessed_chunks.json" ]; then \
        echo "βœ… Chunks file found at all_books_preprocessed_chunks.json"; \
        echo "πŸ“Š File size: $(du -h all_books_preprocessed_chunks.json)"; \
    else \
        echo "⚠️ Warning: all_books_preprocessed_chunks.json not found at root"; \
        echo "πŸ“ Contents of root directory:"; \
        ls -la *.json || echo "No JSON files found"; \
    fi

# Ensure all files have correct permissions
RUN chmod -R 755 /app
RUN chmod +x main.py

# Expose the port for FastAPI
EXPOSE 7860

# Environment variables for FastAPI and Hugging Face Spaces
ENV PYTHONPATH="/app:$PYTHONPATH"
ENV UVICORN_HOST="0.0.0.0"
ENV UVICORN_PORT="7860"
ENV UVICORN_LOG_LEVEL="info"

# Variables to optimize performance
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1

# Variables for cache management
ENV MAX_CACHE_SIZE_MB=500
ENV MAX_CACHE_AGE_DAYS=7

# Healthcheck to verify the application is responding
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
    CMD curl -f http://localhost:7860/health || exit 1

# Command to launch the FastAPI application
CMD ["python", "main.py"]