File size: 1,524 Bytes
4d55e84
5511aad
 
4d55e84
5511aad
 
f238bbd
5511aad
 
 
 
4d55e84
5511aad
 
4d55e84
 
 
5511aad
4d55e84
 
 
 
 
 
 
 
b136104
cb7e73c
4d55e84
 
 
 
 
 
 
 
cb7e73c
 
4d55e84
 
 
 
 
 
 
 
 
 
5511aad
a55dc06
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
# Use Python 3.9 slim image
FROM python:3.9-slim

# Set working directory
WORKDIR /app

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

# Copy requirements and install Python dependencies
COPY requirements.txt ./
RUN pip3 install --no-cache-dir -r requirements.txt

# Set NLTK data directory to a location with proper permissions
ENV NLTK_DATA=/usr/local/share/nltk_data
RUN mkdir -p $NLTK_DATA

# Download NLTK data as root (with permissions) and handle SSL issues
RUN python -c "import ssl; ssl._create_default_https_context = ssl._create_unverified_context; import nltk; nltk.download('stopwords', download_dir='/usr/local/share/nltk_data'); nltk.download('wordnet', download_dir='/usr/local/share/nltk_data'); nltk.download('omw-1.4', download_dir='/usr/local/share/nltk_data')"

# Copy the application code
COPY . .

# Create necessary directories with proper permissions
RUN mkdir -p models artifacts vectorizers
RUN chmod -R 755 models artifacts vectorizers

# Create a non-root user for security
RUN useradd -m -u 1000 user
RUN chown -R user:user /app
USER user

# Set environment variables
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH \
    PYTHONPATH=/app \
    NLTK_DATA=/usr/local/share/nltk_data

# Expose the port that Streamlit runs on
EXPOSE 8501

# Run the application
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]