File size: 1,046 Bytes
a0697c8
 
 
 
 
 
 
 
 
 
dbea75b
 
 
 
 
 
a0697c8
 
 
 
4b30e2b
a0697c8
4b30e2b
a0697c8
dbea75b
 
 
a0697c8
 
57afa22
b53d446
 
 
 
 
 
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
# Use an official Python runtime as a parent image
FROM python:3.10-slim

# Install system dependencies (poppler-utils and tesseract-ocr)
RUN apt-get update && apt-get install -y \
    poppler-utils \
    tesseract-ocr \
    libtesseract-dev \
    && rm -rf /var/lib/apt/lists/*

# Create a non-root user
RUN useradd -m appuser

# Set working directory
WORKDIR /app

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

# Copy the app code and templates
COPY app.py .
COPY templates /app/templates/

# Switch to non-root user
USER appuser

EXPOSE 7860

ENV PYTHONUNBUFFERED=1
ENV FLASK_APP=app.py

# Gunicorn with increased timeout and gevent workers for better handling of I/O bound tasks (like network/file ops)
# Adjust workers based on your Space's CPU cores.
# Timeout is for a single request/response cycle. Streaming should keep this alive.
CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "1", "--worker-class", "gevent", "--timeout", "300", "app:app"]