signflow2 / Dockerfile
LouisVasseur's picture
Use socketio dev server with logging
c58625c
Raw
History Blame Contribute Delete
2.72 kB
# =============================================================================
# SignFlow - Hugging Face Spaces Build (Docker SDK, port 7860)
# =============================================================================
# Stage 1: Build React frontend
FROM node:20-slim AS frontend-builder
WORKDIR /app
COPY package.json ./
RUN npm install
COPY index.html vite.config.ts tsconfig.json tsconfig.node.json ./
COPY src ./src
RUN npm run build
# Stage 2: Python backend
FROM python:3.11-slim
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
libgl1 \
libglib2.0-0 \
libsm6 \
libxext6 \
libxrender1 \
libgomp1 \
curl \
&& rm -rf /var/lib/apt/lists/*
# HF Spaces requires non-root user
RUN useradd -m -u 1000 user
USER user
ENV PATH="/home/user/.local/bin:$PATH"
WORKDIR /home/user/app
# Install Python dependencies
COPY --chown=user server/requirements.txt ./
RUN pip install --no-cache-dir --user -r requirements.txt gunicorn huggingface_hub
# Copy backend code
COPY --chown=user server/ ./
# Copy built frontend
COPY --chown=user --from=frontend-builder /app/dist ./dist
# Create model directory
RUN mkdir -p /home/user/app/models
# Model download script
COPY --chown=user <<'SCRIPT' /home/user/app/download_model.sh
#!/bin/bash
set -e
MODEL_PATH="/home/user/app/models/best_model.pth"
GLOSS_PATH="/home/user/app/models/gloss_map.csv"
if [ ! -f "$MODEL_PATH" ]; then
echo "πŸ“₯ Downloading model from Hugging Face..."
python -c "
from huggingface_hub import hf_hub_download
import shutil, os
repo_id = os.environ.get('HF_REPO_ID', 'LouisVasseur/signflow-model')
# Download model
model_file = hf_hub_download(repo_id=repo_id, filename='best_model.pth', cache_dir='/tmp/hf_cache')
shutil.copy(model_file, '$MODEL_PATH')
print(f'βœ“ Model: {os.path.getsize(\"$MODEL_PATH\") / 1e6:.1f} MB')
# Download gloss map (try common names)
for fname in ['gloss_mapping.csv', 'gloss_map.csv', 'glosses.csv']:
try:
gloss_file = hf_hub_download(repo_id=repo_id, filename=fname, cache_dir='/tmp/hf_cache')
shutil.copy(gloss_file, '$GLOSS_PATH')
print(f'βœ“ Gloss map: {fname}')
break
except Exception:
continue
else:
print('⚠ No gloss map found in HF repo, using default')
"
fi
echo "πŸš€ Starting SignFlow on port 7860..."
exec "$@"
SCRIPT
RUN chmod +x /home/user/app/download_model.sh
# Environment
ENV PORT=7860
ENV MODEL_PATH=/home/user/app/models/best_model.pth
ENV GLOSS_MAP_PATH=/home/user/app/models/gloss_map.csv
ENV PYTHONUNBUFFERED=1
ENV HF_REPO_ID=LouisVasseur/signflow-model
EXPOSE 7860
ENTRYPOINT ["/home/user/app/download_model.sh"]
CMD ["python", "app.py"]