Spaces:
Running
Running
Update Dockerfile
Browse files- Dockerfile +61 -6
Dockerfile
CHANGED
|
@@ -24,16 +24,71 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|
| 24 |
# Copy all app code
|
| 25 |
COPY . /app/
|
| 26 |
|
| 27 |
-
#
|
|
|
|
|
|
|
|
|
|
| 28 |
RUN if [ -f /app/scripts/entrypoint_hf.sh ]; then \
|
| 29 |
-
mv /app/scripts/entrypoint_hf.sh /app/scripts/entrypoint.sh
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
chmod +x /app/scripts/entrypoint.sh; \
|
| 33 |
fi
|
| 34 |
|
|
|
|
|
|
|
|
|
|
| 35 |
# Hugging Face Spaces uses port 7860
|
| 36 |
EXPOSE 7860
|
| 37 |
|
| 38 |
-
# Use entrypoint script
|
| 39 |
-
ENTRYPOINT ["/app/scripts/entrypoint.sh"]
|
|
|
|
| 24 |
# Copy all app code
|
| 25 |
COPY . /app/
|
| 26 |
|
| 27 |
+
# Debug: List what's in scripts directory
|
| 28 |
+
RUN ls -la /app/scripts/ || echo "Scripts directory not found"
|
| 29 |
+
|
| 30 |
+
# Handle entrypoint - check both possible names and create if needed
|
| 31 |
RUN if [ -f /app/scripts/entrypoint_hf.sh ]; then \
|
| 32 |
+
mv /app/scripts/entrypoint_hf.sh /app/scripts/entrypoint.sh && \
|
| 33 |
+
chmod +x /app/scripts/entrypoint.sh; \
|
| 34 |
+
elif [ -f /app/scripts/entrypoint.sh ]; then \
|
| 35 |
+
chmod +x /app/scripts/entrypoint.sh; \
|
| 36 |
+
else \
|
| 37 |
+
echo "Creating entrypoint.sh from template..." && \
|
| 38 |
+
mkdir -p /app/scripts && \
|
| 39 |
+
cat > /app/scripts/entrypoint.sh << 'EOF' \
|
| 40 |
+
#!/bin/sh
|
| 41 |
+
set -eu
|
| 42 |
+
|
| 43 |
+
# Download Asripa model if not present
|
| 44 |
+
ASRIPA_MODEL_DIR="/app/models/fine_tuned_vit"
|
| 45 |
+
ASRIPA_MODEL_ID="${ASRIPA_MODEL_ID:-HimAJ/asripa-emotion-detection}"
|
| 46 |
+
|
| 47 |
+
if [ -n "$ASRIPA_MODEL_ID" ] && [ ! -f "$ASRIPA_MODEL_DIR/model.safetensors" ]; then
|
| 48 |
+
echo "📥 Downloading Asripa model from HuggingFace..."
|
| 49 |
+
echo " Model ID: $ASRIPA_MODEL_ID"
|
| 50 |
+
mkdir -p "$ASRIPA_MODEL_DIR"
|
| 51 |
+
|
| 52 |
+
python3 -c "
|
| 53 |
+
from huggingface_hub import snapshot_download
|
| 54 |
+
import os
|
| 55 |
+
import sys
|
| 56 |
+
try:
|
| 57 |
+
snapshot_download(
|
| 58 |
+
repo_id='$ASRIPA_MODEL_ID',
|
| 59 |
+
local_dir='$ASRIPA_MODEL_DIR',
|
| 60 |
+
local_dir_use_symlinks=False
|
| 61 |
+
)
|
| 62 |
+
print('✅ Asripa model downloaded successfully!')
|
| 63 |
+
except Exception as e:
|
| 64 |
+
print(f'⚠️ Failed to download Asripa model: {e}')
|
| 65 |
+
print(' App will use base model only')
|
| 66 |
+
import shutil
|
| 67 |
+
if os.path.exists('$ASRIPA_MODEL_DIR'):
|
| 68 |
+
shutil.rmtree('$ASRIPA_MODEL_DIR')
|
| 69 |
+
sys.exit(0)
|
| 70 |
+
" || {
|
| 71 |
+
echo "⚠️ Asripa model download skipped"
|
| 72 |
+
rm -rf "$ASRIPA_MODEL_DIR" 2>/dev/null || true
|
| 73 |
+
}
|
| 74 |
+
elif [ -f "$ASRIPA_MODEL_DIR/model.safetensors" ]; then
|
| 75 |
+
echo "✅ Asripa model already present"
|
| 76 |
+
fi
|
| 77 |
+
|
| 78 |
+
# Start app on port 7860
|
| 79 |
+
PORT="${PORT:-7860}"
|
| 80 |
+
echo "Starting gunicorn on 0.0.0.0:${PORT}"
|
| 81 |
+
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
|
| 82 |
+
exec gunicorn main:app --bind 0.0.0.0:"${PORT}" --workers 1 --threads 1 --timeout 120 --worker-class gthread
|
| 83 |
+
EOF
|
| 84 |
chmod +x /app/scripts/entrypoint.sh; \
|
| 85 |
fi
|
| 86 |
|
| 87 |
+
# Verify entrypoint exists
|
| 88 |
+
RUN ls -la /app/scripts/entrypoint.sh || (echo "ERROR: entrypoint.sh not found!" && exit 1)
|
| 89 |
+
|
| 90 |
# Hugging Face Spaces uses port 7860
|
| 91 |
EXPOSE 7860
|
| 92 |
|
| 93 |
+
# Use entrypoint script
|
| 94 |
+
ENTRYPOINT ["/app/scripts/entrypoint.sh"]
|