Spaces:
Sleeping
Sleeping
| # Multi-stage build for NullAI Phi-4 Knowledge System | |
| # Optimized for HuggingFace Spaces deployment | |
| # Stage 1: Build frontend | |
| FROM node:18-alpine AS frontend-builder | |
| WORKDIR /app/frontend | |
| # Copy package files | |
| COPY frontend/package*.json ./ | |
| # Install dependencies (including devDependencies for build tools like TypeScript) | |
| RUN npm ci | |
| # Add execute permissions to fix build issues on some platforms | |
| RUN chmod +x /app/frontend/node_modules/.bin/tsc /app/frontend/node_modules/.bin/vite | |
| # Copy frontend source | |
| COPY frontend/ ./ | |
| # Build frontend | |
| RUN npm run build | |
| # Stage 2: Python backend | |
| FROM python:3.11-slim | |
| LABEL maintainer="Kodai Motonishi <kodai820820@gmail.com>" | |
| LABEL description="NullAI Phi-4 14B Knowledge Management System" | |
| WORKDIR /app | |
| # Install system dependencies | |
| RUN apt-get update && apt-get install -y \ | |
| gcc \ | |
| g++ \ | |
| make \ | |
| curl \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Copy backend requirements | |
| COPY backend/requirements.txt ./backend/ | |
| # Install Python dependencies | |
| RUN pip install --no-cache-dir --upgrade pip && \ | |
| pip install --no-cache-dir -r backend/requirements.txt | |
| # Copy backend code | |
| COPY backend/ ./backend/ | |
| # Copy null_ai module | |
| COPY null_ai/ ./null_ai/ | |
| # Copy frontend build from previous stage | |
| COPY --from=frontend-builder /app/frontend/dist ./frontend/dist | |
| # Copy configuration files | |
| COPY models_config.json domains_config.json null_ai_config.json ./ | |
| # Create default config files if they don't exist | |
| RUN if [ ! -f models_config.json ]; then \ | |
| echo '{"models": [{"model_id": "nullai", "display_name": "NullAI", "provider": "huggingface", "model_name": "kofdai/nullai-phi-4-14b-v2", "max_tokens": 4096, "temperature": 0.7, "timeout": 120, "is_default": true, "supported_domains": ["medical", "general"]}]}' > models_config.json; \ | |
| fi && \ | |
| if [ ! -f domains_config.json ]; then \ | |
| echo '{"domains": [{"domain_id": "general", "display_name": "General", "description": "General knowledge", "default_model_id": "nullai"}]}' > domains_config.json; \ | |
| fi && \ | |
| if [ ! -f null_ai_config.json ]; then \ | |
| echo '{"active_domain_id": "general", "main_db_path": "data/nullai_knowledge.iath", "db_provider": "iath"}' > null_ai_config.json; \ | |
| fi | |
| # Copy utility scripts | |
| COPY db_manager.py inference_engine_unified.py runner_engine.py ./ | |
| # Copy import tools | |
| COPY import_iath.py batch_import_iath.sh ./ | |
| COPY hot_cache.py ./ | |
| # Create necessary directories | |
| RUN mkdir -p /app/data /app/uploads | |
| # Set environment variables for HuggingFace Spaces | |
| ENV PYTHONPATH=/app | |
| ENV PYTHONUNBUFFERED=1 | |
| ENV HOST=0.0.0.0 | |
| ENV PORT=7860 | |
| # Database configuration | |
| ENV DATABASE_URL=sqlite:////app/data/nullai_knowledge.db | |
| # Security settings | |
| ENV SECRET_KEY=changeme-in-production | |
| # CORS settings (will be updated in Spaces) | |
| ENV CORS_ORIGINS='["https://kofdai-nullai-knowledge-system.hf.space"]' | |
| # Expose port (HuggingFace Spaces standard) | |
| EXPOSE 7860 | |
| # Health check | |
| HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \ | |
| CMD curl -f http://localhost:7860/api/system/health || exit 1 | |
| # Initialize database and start application | |
| CMD python backend/create_db.py && \ | |
| uvicorn backend.app.main:app \ | |
| --host 0.0.0.0 \ | |
| --port 7860 \ | |
| --log-level info | |