Spaces:
Sleeping
Sleeping
| FROM python:3.10-slim | |
| WORKDIR /app | |
| # Install system dependencies + OCR libraries | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| sqlite3 \ | |
| ca-certificates \ | |
| libgomp1 \ | |
| tesseract-ocr \ | |
| tesseract-ocr-eng \ | |
| libglib2.0-0 \ | |
| libsm6 \ | |
| libxext6 \ | |
| libxrender-dev \ | |
| libgl1-mesa-glx \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Verify Tesseract installation | |
| RUN tesseract --version | |
| # Copy requirements and install Python packages | |
| COPY requirements.txt . | |
| RUN pip install --no-cache-dir --upgrade pip && \ | |
| pip install --no-cache-dir -r requirements.txt | |
| # Upgrade Gemini SDK for v1 API | |
| RUN pip install --no-cache-dir --upgrade google-generativeai google-ai-generativelanguage | |
| # Install EasyOCR (best free open-source OCR) + dependencies | |
| RUN pip install --no-cache-dir easyocr opencv-python-headless Pillow pytesseract | |
| # Copy application code | |
| COPY . . | |
| # Create necessary directories | |
| RUN mkdir -p /app/data/logs /app/data/docs /app/backend/app/db && chmod -R 777 /app/data | |
| # Create __init__.py files (INCLUDING AGENT DIRECTORY) | |
| RUN touch backend/__init__.py \ | |
| && touch backend/feature_builder/__init__.py \ | |
| && touch backend/app/__init__.py \ | |
| && touch backend/app/api/__init__.py \ | |
| && touch backend/app/agent/__init__.py \ | |
| && touch backend/app/wrappers/__init__.py \ | |
| && touch backend/app/db/__init__.py \ | |
| && touch backend/ingest/__init__.py | |
| # Verify agent files exist (will fail build if missing) | |
| RUN test -f backend/app/agent/agent_orchestrator.py || \ | |
| (echo "ERROR: agent_orchestrator.py not found! Add it before building." && exit 1) | |
| # ============================================ | |
| # INITIALIZE DATABASE | |
| # ============================================ | |
| # Copy db_init.py to the correct location | |
| COPY backend/app/db/db_init.py backend/app/db/db_init.py | |
| # Run database initialization during build | |
| RUN echo "ποΈ Initializing database during build..." && \ | |
| python backend/app/db/db_init.py && \ | |
| echo "β Database initialized successfully!" | |
| # Expose port | |
| EXPOSE 7860 | |
| # Create startup script that ensures DB exists before running app | |
| RUN echo '#!/bin/bash\n\ | |
| echo "π Checking database..."\n\ | |
| python backend/app/db/db_init.py\n\ | |
| echo "β Database ready"\n\ | |
| echo "π Starting application..."\n\ | |
| exec uvicorn app:app --host 0.0.0.0 --port 7860 --timeout-keep-alive 75\n\ | |
| ' > /app/start.sh && chmod +x /app/start.sh | |
| CMD ["/app/start.sh"] |