FROM python:3.10-slim # Install system dependencies # Added patchelf to fix onnxruntime executable stack error RUN apt-get update && apt-get install -y \ libgl1 \ libglx-mesa0 \ libglib2.0-0 \ wget \ g++ \ build-essential \ patchelf \ && rm -rf /var/lib/apt/lists/* WORKDIR /app # Copy requirements and install COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Fix onnxruntime "cannot enable executable stack" error # This clears the GNU_STACK executable bit on the shared library RUN patchelf --clear-execstack /usr/local/lib/python3.10/site-packages/onnxruntime/capi/onnxruntime_pybind11_state.cpython-310-x86_64-linux-gnu.so # Create a non-root user RUN useradd -m -u 1000 user USER user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH WORKDIR $HOME/app # Pre-download ONNX model during build RUN mkdir -p weights && \ wget -O weights/realesrgan-x2plus.onnx https://huggingface.co/tidus2102/Real-ESRGAN/resolve/main/Real-ESRGAN_x2plus.onnx # Copy the rest of the application COPY --chown=user . . # Expose port 7860 for Hugging Face Spaces EXPOSE 7860 # Run the application CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]