Spaces:
Running
Running
| FROM ghcr.io/astral-sh/uv:python3.10-bookworm-slim as builder | |
| WORKDIR /app | |
| # Copy project files for dependency installation | |
| COPY pyproject.toml /app/ | |
| COPY README.md /app/ | |
| # Show pyproject.toml content | |
| RUN cat pyproject.toml | |
| # Create a virtual environment and install dependencies using uv sync | |
| RUN uv venv /app/.venv && \ | |
| . /app/.venv/bin/activate && \ | |
| uv sync | |
| # Verify installations with the virtual environment | |
| RUN . /app/.venv/bin/activate && \ | |
| python -c "import numpy; print(f'NumPy version: {numpy.__version__}')" && \ | |
| python -c "import pandas; print(f'Pandas version: {pandas.__version__}')" && \ | |
| python -c "import uvicorn; print(f'Uvicorn version: {uvicorn.__version__}')" | |
| # Second stage for the final image | |
| FROM ghcr.io/astral-sh/uv:python3.10-bookworm-slim | |
| # Add user - this is the user that will run the app | |
| RUN useradd -m -u 1000 user | |
| # Copy the virtual environment from the builder stage | |
| COPY --from=builder /app/.venv /home/user/app/.venv | |
| # Install Node.js for building the frontend | |
| RUN apt-get update && apt-get install -y \ | |
| curl \ | |
| gnupg \ | |
| && curl -sL https://deb.nodesource.com/setup_18.x | bash - \ | |
| && apt-get install -y nodejs \ | |
| && apt-get clean \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Set up user environment | |
| ENV HOME=/home/user \ | |
| PATH=/home/user/app/.venv/bin:$PATH \ | |
| UVICORN_WS_PROTOCOL=websockets \ | |
| FORWARDED_ALLOW_IPS="*" \ | |
| HTTPTOOLS_LOG_DEBUG=1 | |
| # Verify dependencies are available in the final image | |
| RUN python -c "import numpy; print(f'NumPy version: {numpy.__version__}')" && \ | |
| python -c "import pandas; print(f'Pandas version: {pandas.__version__}')" && \ | |
| python -c "import uvicorn; print(f'Uvicorn version: {uvicorn.__version__}')" | |
| # Copy frontend code and build it | |
| COPY --chown=user frontend /home/user/app/frontend | |
| USER user | |
| WORKDIR /home/user/app/frontend | |
| RUN npm install && npm run build | |
| # Copy backend code | |
| WORKDIR /home/user/app | |
| COPY --chown=user backend /home/user/app/backend | |
| # Copy aimakerspace module | |
| COPY --chown=user aimakerspace /home/user/app/aimakerspace | |
| # Set the working directory to the backend folder | |
| WORKDIR /home/user/app/backend | |
| # Expose port for FastAPI on Hugging Face | |
| EXPOSE 7860 | |
| # Start the FastAPI server with optimized settings for Hugging Face Spaces | |
| CMD ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--proxy-headers", "--forwarded-allow-ips=*", "--timeout-keep-alive", "75"] |