File size: 2,164 Bytes
2d9ee72
 
4047b5f
2d9ee72
 
4047b5f
 
 
 
 
 
2d9ee72
 
4047b5f
 
2d9ee72
 
4047b5f
2d9ee72
 
4047b5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2d9ee72
 
4047b5f
 
2d9ee72
 
4047b5f
 
 
2d9ee72
 
 
4047b5f
 
 
 
 
2d9ee72
 
4047b5f
 
 
 
2d9ee72
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.11-slim

# Set working directory
WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y \
    gcc \
    g++ \
    && rm -rf /var/lib/apt/lists/*

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

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

# Copy the entire application
COPY . .

# Create necessary directories with write permissions
RUN mkdir -p uploads saved_sessions .streamlit
RUN chmod -R 777 uploads saved_sessions

# Create Streamlit config to fix 403 error
RUN echo '[server]' > .streamlit/config.toml && \
    echo 'maxUploadSize = 200' >> .streamlit/config.toml && \
    echo 'enableCORS = true' >> .streamlit/config.toml && \
    echo 'enableXsrfProtection = false' >> .streamlit/config.toml && \
    echo 'address = "0.0.0.0"' >> .streamlit/config.toml && \
    echo 'port = 7860' >> .streamlit/config.toml && \
    echo '' >> .streamlit/config.toml && \
    echo '[browser]' >> .streamlit/config.toml && \
    echo 'gatherUsageStats = false' >> .streamlit/config.toml && \
    echo '' >> .streamlit/config.toml && \
    echo '[theme]' >> .streamlit/config.toml && \
    echo 'base = "dark"' >> .streamlit/config.toml && \
    echo 'primaryColor = "#00ff9d"' >> .streamlit/config.toml && \
    echo 'backgroundColor = "#0a0e17"' >> .streamlit/config.toml && \
    echo 'secondaryBackgroundColor = "#111827"' >> .streamlit/config.toml && \
    echo 'textColor = "#e8e8e8"' >> .streamlit/config.toml

# Create a user for security
RUN useradd -m -u 1000 user
USER user

# Set environment variables
ENV HOME=/home/user
ENV PATH=/home/user/.local/bin:$PATH
ENV PYTHONUNBUFFERED=1

# Copy files with correct ownership
WORKDIR $HOME/app
COPY --chown=user . $HOME/app

# Ensure directories exist and have correct permissions
RUN mkdir -p uploads saved_sessions
RUN chmod -R 777 uploads saved_sessions

# Expose the port Hugging Face Spaces uses
EXPOSE 7860

# Health check
HEALTHCHECK CMD curl --fail http://localhost:7860/_stcore/health || exit 1

# Run the Streamlit app
CMD ["streamlit", "run", "app/main.py", "--server.port=7860", "--server.address=0.0.0.0"]