Spaces:
Runtime error
Runtime error
Update requirements.txt
Browse files- requirements.txt +63 -4
requirements.txt
CHANGED
|
@@ -1,4 +1,63 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use an official Python runtime as a parent image
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Set environment variables to prevent interactive prompts during apt-get install
|
| 5 |
+
ENV DEBIAN_FRONTEND=noninteractive
|
| 6 |
+
|
| 7 |
+
# Install system dependencies
|
| 8 |
+
# - Essential for Pillow/OpenCV: libgl1-mesa-glx, libglib2.0-0
|
| 9 |
+
# - Font handling: fontconfig
|
| 10 |
+
# - Installs Microsoft Core Fonts (including Arial): ttf-mscorefonts-installer
|
| 11 |
+
RUN apt-get update && \
|
| 12 |
+
apt-get install -y --no-install-recommends \
|
| 13 |
+
libgl1-mesa-glx \
|
| 14 |
+
libglib2.0-0 \
|
| 15 |
+
fontconfig \
|
| 16 |
+
# Accept the EULA for ttf-mscorefonts-installer non-interactively
|
| 17 |
+
&& echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections \
|
| 18 |
+
&& apt-get install -y --no-install-recommends ttf-mscorefonts-installer \
|
| 19 |
+
&& apt-get clean \
|
| 20 |
+
&& rm -rf /var/lib/apt/lists/* \
|
| 21 |
+
# Update font cache to make installed fonts available
|
| 22 |
+
&& fc-cache -f -v
|
| 23 |
+
|
| 24 |
+
# Set the working directory in the container
|
| 25 |
+
WORKDIR /app
|
| 26 |
+
|
| 27 |
+
# Create a non-root user and group for better security
|
| 28 |
+
# Using user ID 1000 as is common in HF Spaces
|
| 29 |
+
RUN groupadd -g 1000 appuser && useradd --no-log-init -u 1000 -g appuser appuser
|
| 30 |
+
|
| 31 |
+
# Create necessary application directories before copying and set ownership
|
| 32 |
+
# Ensures the user 'appuser' can write to generated_images
|
| 33 |
+
RUN mkdir -p /app/templates /app/generated_images && \
|
| 34 |
+
chown -R appuser:appuser /app
|
| 35 |
+
|
| 36 |
+
# Copy the requirements file first for layer caching
|
| 37 |
+
# Ensure ownership is set correctly during copy
|
| 38 |
+
COPY --chown=appuser:appuser requirements.txt .
|
| 39 |
+
|
| 40 |
+
# Install Python dependencies specified in requirements.txt
|
| 41 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 42 |
+
|
| 43 |
+
# Copy the rest of the application files into the container
|
| 44 |
+
# Ensure 'app.py', 'arial.ttf', and the 'templates' directory exist in your repo root
|
| 45 |
+
COPY --chown=appuser:appuser app.py .
|
| 46 |
+
|
| 47 |
+
# ---- IMPORTANT ----
|
| 48 |
+
# The following line requires 'arial.ttf' to be present in the root of your repository
|
| 49 |
+
COPY --chown=appuser:appuser arial.ttf .
|
| 50 |
+
# ---- IMPORTANT ----
|
| 51 |
+
|
| 52 |
+
# Copy the entire templates directory
|
| 53 |
+
COPY --chown=appuser:appuser templates ./templates
|
| 54 |
+
|
| 55 |
+
# Switch to the non-root user
|
| 56 |
+
USER appuser
|
| 57 |
+
|
| 58 |
+
# Define environment variable placeholder (Hugging Face Secrets will override this)
|
| 59 |
+
# You MUST set TELEGRAM_TOKEN in your Space's secrets settings.
|
| 60 |
+
ENV TELEGRAM_TOKEN=""
|
| 61 |
+
|
| 62 |
+
# Command to run the application when the container launches
|
| 63 |
+
CMD ["python", "app.py"]
|