# Use Python 3.9 for compatibility with fairseq-signals FROM python:3.9-slim ENV PYTHONUNBUFFERED=1 \ HF_HOME=/app/.cache/huggingface \ PORT=7860 RUN apt-get update && apt-get install -y --no-install-recommends \ git \ build-essential \ && rm -rf /var/lib/apt/lists/* WORKDIR /app COPY requirements.txt . # Step 1: Install NumPy 1.26.4 FIRST for PyTorch 2.1.0 + ECG-FM compatibility RUN echo 'Installing NumPy 1.26.4 for PyTorch 2.1.0 + ECG-FM compatibility...' && \ pip install --no-cache-dir 'numpy==1.26.4' && \ echo 'NumPy 1.26.4 installed successfully' # Step 2: Install all requirements (PyTorch 2.1.0, transformers 4.21.0, etc.) RUN pip install --no-cache-dir -r requirements.txt # Step 3: Clone and install fairseq-signals from the correct repository RUN echo 'Step 1: Cloning fairseq-signals repository...' && \ git clone https://github.com/Jwoo5/fairseq-signals.git && \ echo 'Step 2: Repository cloned successfully' RUN echo 'Step 3: Installing fairseq-signals without C++ extensions...' && \ cd fairseq-signals && \ pip install --editable ./ --no-build-isolation && \ echo 'Step 4: fairseq_signals installed successfully' # Step 4: CRITICAL - Reinstall NumPy 1.26.4 after fairseq-signals to prevent version conflict RUN echo 'CRITICAL: Reinstalling NumPy 1.26.4 after fairseq-signals to prevent version conflict...' && \ pip install --force-reinstall --no-cache-dir 'numpy==1.26.4' && \ python -c "import numpy; print(f'✅ NumPy version confirmed: {numpy.__version__}')" && \ echo 'NumPy 1.26.4 reinstalled successfully - ECG-FM compatibility restored' # Create cache directories with proper permissions RUN mkdir -p /app/.cache/huggingface /app/.cache/matplotlib && \ chmod -R 777 /app/.cache COPY . . EXPOSE 7860 # Use fallback server that can work without fairseq-signals CMD ["uvicorn", "server.server:app", "--host", "0.0.0.0", "--port", "7860"]