FROM python:3.9-slim # Set environment variables ENV PYTHONUNBUFFERED=1 ENV DEBIAN_FRONTEND=noninteractive ENV BUILD_ID="$(date +%s)_$(echo $RANDOM)" # Install system dependencies RUN apt-get update && apt-get install -y --no-install-recommends git build-essential && rm -rf /var/lib/apt/lists/* # Create app user with optimized cache directories for HF loading strategy RUN useradd --create-home --shell /bin/bash app && \ mkdir -p /app/.cache/huggingface /app/.cache/transformers /app/.config/matplotlib && \ chown -R app:app /app WORKDIR /app # Copy requirements file COPY requirements_hf_spaces.txt . # CRITICAL FIX: Install NumPy 1.26.4 for PyTorch 2.1.0 + ECG-FM compatibility # This version satisfies wfdb (>=1.26.4) and is compatible with PyTorch 2.x 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' # Install Python dependencies (PyTorch 2.1.0 + all other packages) RUN pip install --no-cache-dir -r requirements_hf_spaces.txt # CRITICAL FIX: Install fairseq-signals with proper error handling # Break down the installation into separate steps to avoid shell command issues 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' RUN echo 'Step 5: Verifying fairseq_signals import...' && \ python -c "import fairseq_signals; print('✅ fairseq_signals imported successfully (without C++ extensions)')" && \ echo 'fairseq_signals installation verified - C++ extensions skipped for compatibility' # CRITICAL FIX: Force reinstall NumPy 1.26.4 to prevent overwrite by fairseq_signals # fairseq_signals installation pulls transformers which overwrites NumPy with 2.0.2 # This step ensures ECG-FM compatibility is maintained 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' # Copy application files (updated 2025-08-25 14:15 UTC - PyTorch 2.x compatibility for ECG-FM weight_norm function) # Build trigger attempt #11 - PyTorch 2.x compatibility for ECG-FM weight_norm function COPY . . # Switch to app user USER app # Expose port EXPOSE 7860 # Start the application CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "7860"]