Spaces:
Sleeping
Sleeping
| # Use an official Python image as a base | |
| FROM python:3.9 | |
| # Set environment variables | |
| ENV PYTHONUNBUFFERED=1 \ | |
| PORT=7860 \ | |
| PYTHONPATH=/app \ | |
| HOME=/home/chrome \ | |
| CHROME_BIN=/usr/bin/google-chrome \ | |
| TRANSFORMERS_CACHE=/app/.cache \ | |
| HF_HOME=/app/.cache | |
| # Create chrome user | |
| RUN mkdir -p /home/chrome && \ | |
| groupadd -r chrome && \ | |
| useradd -r -g chrome -G audio,video chrome && \ | |
| mkdir -p /home/chrome/Downloads && \ | |
| chown -R chrome:chrome /home/chrome | |
| # Set the working directory | |
| WORKDIR /app | |
| # Install system dependencies including Chrome | |
| RUN apt-get update && apt-get install -y \ | |
| build-essential \ | |
| wget \ | |
| gnupg \ | |
| unzip \ | |
| xvfb \ | |
| && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \ | |
| && echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list \ | |
| && apt-get update \ | |
| && apt-get install -y google-chrome-stable \ | |
| && chown -R chrome:chrome /usr/bin/google-chrome \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Create cache directory and set permissions | |
| RUN mkdir -p /app/.cache && chown -R chrome:chrome /app/.cache | |
| # Copy requirements file | |
| COPY requirements.txt . | |
| # Install Python dependencies and pre-download the model | |
| RUN pip install --no-cache-dir -r requirements.txt \ | |
| && pip install --no-cache-dir hypercorn sentence-transformers \ | |
| && python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('all-MiniLM-L6-v2')" | |
| # Copy the current directory contents into the container | |
| COPY . /app | |
| # Set permissions | |
| RUN chown -R chrome:chrome /app | |
| # Switch to chrome user | |
| USER chrome | |
| # Make port 7860 available to the world outside this container | |
| EXPOSE 7860 | |
| # Run the app with Hypercorn | |
| CMD ["hypercorn", "app:app", "--bind", "0.0.0.0:7860"] | |