HimAJ commited on
Commit
96b63cd
·
verified ·
1 Parent(s): 8ea1484

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +24 -59
Dockerfile CHANGED
@@ -25,67 +25,32 @@ RUN pip install --no-cache-dir -r requirements.txt
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
 
25
  COPY . /app/
26
 
27
  # Debug: List what's in scripts directory
28
+ RUN ls -la /app/scripts/ 2>/dev/null || echo "Scripts directory not found"
29
+
30
+ # Handle entrypoint - rename if needed, or create simple one
31
+ RUN mkdir -p /app/scripts && \
32
+ if [ -f /app/scripts/entrypoint_hf.sh ]; then \
33
+ mv /app/scripts/entrypoint_hf.sh /app/scripts/entrypoint.sh; \
34
+ elif [ ! -f /app/scripts/entrypoint.sh ]; then \
35
+ echo '#!/bin/sh' > /app/scripts/entrypoint.sh && \
36
+ echo 'set -eu' >> /app/scripts/entrypoint.sh && \
37
+ echo 'ASRIPA_MODEL_DIR="/app/models/fine_tuned_vit"' >> /app/scripts/entrypoint.sh && \
38
+ echo 'ASRIPA_MODEL_ID="${ASRIPA_MODEL_ID:-HimAJ/asripa-emotion-detection}"' >> /app/scripts/entrypoint.sh && \
39
+ echo 'if [ -n "$ASRIPA_MODEL_ID" ] && [ ! -f "$ASRIPA_MODEL_DIR/model.safetensors" ]; then' >> /app/scripts/entrypoint.sh && \
40
+ echo ' echo "📥 Downloading Asripa model from HuggingFace..."' >> /app/scripts/entrypoint.sh && \
41
+ echo ' echo " Model ID: $ASRIPA_MODEL_ID"' >> /app/scripts/entrypoint.sh && \
42
+ echo ' mkdir -p "$ASRIPA_MODEL_DIR"' >> /app/scripts/entrypoint.sh && \
43
+ 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 && \
44
+ echo 'fi' >> /app/scripts/entrypoint.sh && \
45
+ echo 'PORT="${PORT:-7860}"' >> /app/scripts/entrypoint.sh && \
46
+ echo 'echo "Starting gunicorn on 0.0.0.0:${PORT}"' >> /app/scripts/entrypoint.sh && \
47
+ echo 'export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python' >> /app/scripts/entrypoint.sh && \
48
+ echo 'exec gunicorn main:app --bind 0.0.0.0:"${PORT}" --workers 1 --threads 1 --timeout 120 --worker-class gthread' >> /app/scripts/entrypoint.sh; \
49
+ fi && \
50
+ chmod +x /app/scripts/entrypoint.sh
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
  # Verify entrypoint exists
53
+ RUN test -f /app/scripts/entrypoint.sh || (echo "ERROR: entrypoint.sh not found!" && exit 1)
54
 
55
  # Hugging Face Spaces uses port 7860
56
  EXPOSE 7860