File size: 2,793 Bytes
1e4fc28
 
 
 
 
 
 
 
 
 
 
 
 
 
11a78de
1e4fc28
 
 
 
 
 
 
 
11a78de
1e4fc28
 
8ea1484
96b63cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1e4fc28
8ea1484
96b63cd
8ea1484
1e4fc28
 
 
8ea1484
 
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
# Dockerfile for Hugging Face Spaces
FROM python:3.11-slim

ENV PYTHONUNBUFFERED=1
WORKDIR /app

# System dependencies for opencv and runtime model download
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    libgl1 \
    libglib2.0-0 \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Copy requirements first (for better caching)
COPY requirements.txt /app/requirements.txt

# Upgrade pip
RUN python -m pip install --upgrade pip setuptools wheel

# Install requirements
RUN pip install --no-cache-dir -r requirements.txt

# Copy all app code
COPY . /app/

# Debug: List what's in scripts directory
RUN ls -la /app/scripts/ 2>/dev/null || echo "Scripts directory not found"

# Handle entrypoint - rename if needed, or create simple one
RUN mkdir -p /app/scripts && \
    if [ -f /app/scripts/entrypoint_hf.sh ]; then \
        mv /app/scripts/entrypoint_hf.sh /app/scripts/entrypoint.sh; \
    elif [ ! -f /app/scripts/entrypoint.sh ]; then \
        echo '#!/bin/sh' > /app/scripts/entrypoint.sh && \
        echo 'set -eu' >> /app/scripts/entrypoint.sh && \
        echo 'ASRIPA_MODEL_DIR="/app/models/fine_tuned_vit"' >> /app/scripts/entrypoint.sh && \
        echo 'ASRIPA_MODEL_ID="${ASRIPA_MODEL_ID:-HimAJ/asripa-emotion-detection}"' >> /app/scripts/entrypoint.sh && \
        echo 'if [ -n "$ASRIPA_MODEL_ID" ] && [ ! -f "$ASRIPA_MODEL_DIR/model.safetensors" ]; then' >> /app/scripts/entrypoint.sh && \
        echo '  echo "📥 Downloading Asripa model from HuggingFace..."' >> /app/scripts/entrypoint.sh && \
        echo '  echo "   Model ID: $ASRIPA_MODEL_ID"' >> /app/scripts/entrypoint.sh && \
        echo '  mkdir -p "$ASRIPA_MODEL_DIR"' >> /app/scripts/entrypoint.sh && \
        echo '  python3 -c "from huggingface_hub import snapshot_download; import os, sys; snapshot_download(repo_id=\"$ASRIPA_MODEL_ID\", local_dir=\"$ASRIPA_MODEL_DIR\", local_dir_use_symlinks=False) or sys.exit(0)" || echo "⚠️  Asripa download skipped"' >> /app/scripts/entrypoint.sh && \
        echo 'fi' >> /app/scripts/entrypoint.sh && \
        echo 'PORT="${PORT:-7860}"' >> /app/scripts/entrypoint.sh && \
        echo 'echo "Starting gunicorn on 0.0.0.0:${PORT}"' >> /app/scripts/entrypoint.sh && \
        echo 'export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python' >> /app/scripts/entrypoint.sh && \
        echo 'exec gunicorn main:app --bind 0.0.0.0:"${PORT}" --workers 1 --threads 1 --timeout 120 --worker-class gthread' >> /app/scripts/entrypoint.sh; \
    fi && \
    chmod +x /app/scripts/entrypoint.sh

# Verify entrypoint exists
RUN test -f /app/scripts/entrypoint.sh || (echo "ERROR: entrypoint.sh not found!" && exit 1)

# Hugging Face Spaces uses port 7860
EXPOSE 7860

# Use entrypoint script
ENTRYPOINT ["/app/scripts/entrypoint.sh"]