# Copyright 2025 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ========================================== # Stage 1: Build the React Frontend # ========================================== FROM node:24-slim AS frontend-build WORKDIR /app/frontend # Copy frontend codebase COPY frontend/package*.json ./ RUN npm install COPY frontend/ ./ RUN npm run build # ========================================== # Stage 2: Build the Unified Python Backend # ========================================== FROM python:3.12-slim # Install system dependencies RUN apt-get update && apt-get install -y \ wget \ tar \ ffmpeg \ unzip \ && rm -rf /var/lib/apt/lists/* # Set environment variables ENV PYTHONUNBUFFERED=1 \ PORT=7860 \ FRONTEND_BUILD=/app/frontend/build \ CACHE_DIR=/cache # Create user with UID 1000 for Hugging Face Spaces security compliance RUN useradd -m -u 1000 user WORKDIR /app # Copy requirements and install python packages COPY requirements.txt ./ RUN pip install --no-cache-dir -r requirements.txt # Copy all python source modules and package files COPY config.py cache_manager.py llm_client.py tts_client.py app.py LICENSE ./ COPY intake/ ./intake/ COPY radiology/ ./radiology/ COPY static/ ./static/ # Copy built React frontend assets from Stage 1 COPY --from=frontend-build /app/frontend/build ./frontend/build # Set up caching directory with unpacked archives RUN mkdir -p /cache/intake /cache/radiology # Copy cache archives COPY cache_archives/intake_cache.zip /tmp/intake_cache.zip COPY cache_archives/radiology_default_cache/ /tmp/radiology_default_cache/ # Extract intake cache RUN unzip -q -o /tmp/intake_cache.zip -d /cache/intake && rm /tmp/intake_cache.zip # Copy radiology cache RUN cp -r /tmp/radiology_default_cache/* /cache/radiology/ && rm -rf /tmp/radiology_default_cache # Set permissions for user 1000 RUN chown -R 1000:1000 /app /cache && chmod -R 777 /cache # Switch to the non-root user USER user EXPOSE 7860 CMD ["gunicorn", "-b", "0.0.0.0:7860", "app:app", "--threads", "4", "--timeout", "600"]