File size: 1,752 Bytes
66fca56
 
 
 
 
 
 
 
4a0cac4
 
 
 
 
66fca56
 
 
 
e067d1a
 
 
 
66fca56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3ac1943
 
 
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
# Use an official Python runtime as a parent image
FROM python:3.10-slim

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Allow statements and log messages to immediately appear in the Knative logs
ENV PYTHONIOENCODING=utf-8
# Set cache directory for Hugging Face libraries to a writable location
ENV HF_HOME=/app/.cache/huggingface
ENV TRANSFORMERS_CACHE=/app/.cache/transformers
# Create the cache directory (optional, libraries might create it, but good practice)
# RUN mkdir -p /app/.cache && chown -R <user>:<group> /app/.cache # Might need user/group if not running as root

# Set the working directory in the container
WORKDIR /app

# Create the cache directory and set permissions *before* copying files
# This ensures the directory exists and is writable by the user running the process
RUN mkdir -p /app/.cache && chmod -R 777 /app/.cache

# Copy the requirements file into the container at /app
COPY requirements.txt .

# Install any needed packages specified in requirements.txt
# Use --no-cache-dir to reduce image size
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r requirements.txt

# Copy the current directory contents into the container at /app
# This includes app.py, index files, model_data_json directory, etc.
COPY . .

# Make port 8080 available to the world outside this container
# Hugging Face Spaces will map $PORT to this internally if needed, but Gunicorn binds to $PORT directly.
# EXPOSE 8080 is more informational here.
EXPOSE 8080

# Define the command to run the application using Gunicorn
# Bind to the standard Hugging Face Spaces port 7860 explicitly
# Use shell form for CMD
CMD gunicorn app:app --bind 0.0.0.0:7860 --workers 1 --timeout 120