Spaces:
Sleeping
Sleeping
| # Use official Python runtime as base image | |
| FROM python:3.11-slim | |
| # Set working directory in container | |
| WORKDIR /app | |
| # Set environment variables | |
| ENV PYTHONUNBUFFERED=1 \ | |
| PYTHONDONTWRITEBYTECODE=1 \ | |
| PIP_NO_CACHE_DIR=1 \ | |
| PIP_DISABLE_PIP_VERSION_CHECK=1 | |
| # Install system dependencies | |
| RUN apt-get update && apt-get install -y \ | |
| build-essential \ | |
| git \ | |
| curl \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Copy requirements file | |
| COPY requirements.txt . | |
| # Install Python dependencies | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Copy application files | |
| COPY . . | |
| # Create directory for ChromaDB persistence | |
| RUN mkdir -p chroma_db | |
| # Expose port for FastAPI (Hugging Face Spaces requirement) | |
| EXPOSE 7860 | |
| # Create a startup script to run setup_db.py first, then app.py | |
| RUN echo '#!/bin/bash\n\ | |
| set -e\n\ | |
| echo "========================================"\n\ | |
| echo "Setting up database..."\n\ | |
| echo "========================================"\n\ | |
| python setup_db.py\n\ | |
| echo ""\n\ | |
| echo "========================================"\n\ | |
| echo "Database setup complete!"\n\ | |
| echo "Starting FastAPI application..."\n\ | |
| echo "========================================"\n\ | |
| uvicorn app:app --host 0.0.0.0 --port 7860' > /app/start.sh && \ | |
| chmod +x /app/start.sh | |
| # Set the default command to run the startup script | |
| CMD ["/bin/bash", "/app/start.sh"] | |