Spaces:
Runtime error
Runtime error
File size: 2,584 Bytes
fb95f15 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | # 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"]
|