File size: 2,125 Bytes
e70050b
3700c55
e70050b
 
 
 
 
 
 
3700c55
 
 
 
e70050b
3700c55
 
 
e70050b
 
 
 
 
 
3700c55
cccae59
e70050b
3700c55
e70050b
 
3700c55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e70050b
 
 
 
 
 
 
 
 
 
 
 
 
 
3700c55
 
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
# SysCRED Docker Configuration for Hugging Face Spaces
# OPTIMIZED version with Distilled Models for faster startup
FROM python:3.10-slim

WORKDIR /app

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PYTHONPATH=/app

# ============================================
# KEY OPTIMIZATION: Use distilled models
# ============================================
ENV SYSCRED_LOAD_ML_MODELS=true
ENV SYSCRED_USE_DISTILLED=true
ENV TRANSFORMERS_CACHE=/app/.cache/huggingface
ENV HF_HOME=/app/.cache/huggingface

# Install system dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    && rm -rf /var/lib/apt/lists/*

# Copy optimized requirements (distilled models, CPU-only torch)
COPY requirements-distilled.txt /app/requirements.txt

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

# ============================================
# PRE-DOWNLOAD DISTILLED MODELS (Build Time)
# This avoids timeout during first request
# ============================================
RUN python -c "from transformers import pipeline; \
    pipeline('sentiment-analysis', model='distilbert-base-uncased-finetuned-sst-2-english'); \
    pipeline('ner', model='dslim/bert-base-NER'); \
    print('✓ Distilled models pre-downloaded')"

# Download small spaCy models
RUN pip install spacy && \
    python -m spacy download en_core_web_sm && \
    python -m spacy download fr_core_news_sm && \
    echo '✓ spaCy models downloaded'

# Pre-download sentence transformer (small version)
RUN python -c "from sentence_transformers import SentenceTransformer; \
    SentenceTransformer('all-MiniLM-L6-v2'); \
    print('✓ Sentence transformer pre-downloaded')"

# Copy application code
COPY syscred/ /app/syscred/

# Create user for HF Spaces (required)
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user
ENV PATH=/home/user/.local/bin:$PATH

WORKDIR /app

EXPOSE 7860

# Run with HF Spaces port (7860)
# Increased workers to 4 for better concurrency, timeout 600s
CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "1", "--threads", "4", "--timeout", "600", "syscred.backend_app:app"]