# Use an official Python runtime as a parent image FROM python:3.9-slim # Set environment variables for Python ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 # Set environment variables for Hugging Face and Matplotlib cache ENV TRANSFORMERS_CACHE=/app/.cache/huggingface ENV HF_HOME=/app/.cache/huggingface ENV MPLCONFIGDIR=/app/.cache/matplotlib RUN mkdir -p /app/.cache # Adding permission for the cache RUN chmod -R 777 /app/.cache # Give write permissions to the /app directory RUN chmod -R 777 /app # Give write permissions to the /data directory #RUN chmod -R 777 /app/data # Create /app/logs directory and set permissions for logging RUN mkdir -p /app/logs && chmod -R 777 /app/logs # Set the working directory WORKDIR /app # Install system dependencies, including libgomp RUN apt-get update && apt-get install -y \ libgl1-mesa-glx \ libgomp1 \ libglib2.0-0 \ && rm -rf /var/lib/apt/lists/* # Copy the requirements file into the container at /app COPY requirements.txt /app/ # Install any needed packages specified in requirements.txt RUN pip install --no-cache-dir --upgrade -r requirements.txt # Create directories for session storage, uploads, and cache RUN mkdir -p /app/flask_sessions /app/uploads /app/data /app/JSON /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 # Copy the rest of the application code to /app COPY . /app/ # Expose the port that the app runs on EXPOSE 7860 # Set environment variables for Flask ENV FLASK_APP=app.py ENV FLASK_ENV=production # Command to run the Flask app using Gunicorn with 1 worker CMD ["gunicorn", "--workers=1", "--bind=0.0.0.0:7860", "--timeout=120", "app:app"]