Spaces:
Sleeping
Sleeping
Create Dockerfile
Browse files- Dockerfile +52 -0
Dockerfile
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Use an official Python runtime as a parent image
|
| 2 |
+
FROM python:3.9-slim
|
| 3 |
+
|
| 4 |
+
# Set environment variables for Python
|
| 5 |
+
ENV PYTHONDONTWRITEBYTECODE 1
|
| 6 |
+
ENV PYTHONUNBUFFERED 1
|
| 7 |
+
|
| 8 |
+
# Set environment variables for Hugging Face and Matplotlib cache
|
| 9 |
+
ENV TRANSFORMERS_CACHE=/app/.cache/huggingface
|
| 10 |
+
ENV HF_HOME=/app/.cache/huggingface
|
| 11 |
+
ENV MPLCONFIGDIR=/app/.cache/matplotlib
|
| 12 |
+
|
| 13 |
+
# Adding permission for the cache
|
| 14 |
+
RUN chmod -R 777 /app/.cache
|
| 15 |
+
|
| 16 |
+
# Give write permissions to the /app directory
|
| 17 |
+
RUN chmod -R 777 /app
|
| 18 |
+
|
| 19 |
+
# Create /app/logs directory and set permissions for logging
|
| 20 |
+
RUN mkdir -p /app/logs && chmod -R 777 /app/logs
|
| 21 |
+
|
| 22 |
+
# Set the working directory
|
| 23 |
+
WORKDIR /app
|
| 24 |
+
|
| 25 |
+
# Install system dependencies, including libgomp
|
| 26 |
+
RUN apt-get update && apt-get install -y \
|
| 27 |
+
libgl1-mesa-glx \
|
| 28 |
+
libgomp1 \
|
| 29 |
+
libglib2.0-0 \
|
| 30 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 31 |
+
|
| 32 |
+
# Copy the requirements file into the container at /app
|
| 33 |
+
COPY requirements.txt /app/
|
| 34 |
+
|
| 35 |
+
# Install any needed packages specified in requirements.txt
|
| 36 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 37 |
+
|
| 38 |
+
# Create directories for session storage, uploads, and cache
|
| 39 |
+
RUN mkdir -p /app/flask_sessions /app/uploads /app/JSON /app/data /app/Models /tmp/matplotlib /tmp/transformers_cache && chmod -R 777 /app/flask_sessions /app/uploads /app/JSON /app/data /app/Models /tmp/matplotlib /tmp/transformers_cache
|
| 40 |
+
|
| 41 |
+
# Copy the rest of the application code to /app
|
| 42 |
+
COPY . /app/
|
| 43 |
+
|
| 44 |
+
# Expose the port that the app runs on
|
| 45 |
+
EXPOSE 7860
|
| 46 |
+
|
| 47 |
+
# Set environment variables for Flask
|
| 48 |
+
ENV FLASK_APP=app.py
|
| 49 |
+
ENV FLASK_ENV=production
|
| 50 |
+
|
| 51 |
+
# Command to run the Flask app using Gunicorn with 1 worker
|
| 52 |
+
CMD ["gunicorn", "--workers=1", "--bind=0.0.0.0:7860", "--timeout=120", "app:app"]
|