File size: 1,404 Bytes
25bda12
 
 
5913b23
25bda12
 
 
 
 
 
 
 
 
 
 
 
6dc7352
 
 
 
 
 
 
 
 
 
 
 
25bda12
 
 
 
 
 
14d81e7
 
 
25bda12
 
 
 
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
# ---------- build frontend ----------
FROM node:20-bookworm AS frontend-build
WORKDIR /frontend
COPY frontend/package.json ./
RUN npm install
COPY frontend/ .
RUN npm run build

# ---------- runtime ----------
FROM python:3.11-slim
WORKDIR /app

# Backend deps
COPY backend/requirements.txt /app/backend/requirements.txt
RUN pip install --no-cache-dir -r /app/backend/requirements.txt

# Download and save model during build (so it persists across restarts)
# This prevents re-downloading the model on every container restart
RUN mkdir -p /app/Model/bert-tiny && \
    python3 -c "from transformers import AutoTokenizer, AutoModel; \
    print('Downloading BERT-tiny model during build...'); \
    tokenizer = AutoTokenizer.from_pretrained('prajjwal1/bert-tiny'); \
    model = AutoModel.from_pretrained('prajjwal1/bert-tiny'); \
    print('Saving model to /app/Model/bert-tiny...'); \
    tokenizer.save_pretrained('/app/Model/bert-tiny'); \
    model.save_pretrained('/app/Model/bert-tiny'); \
    print('Model saved successfully!')"

# Copy backend code
COPY backend /app/backend

# Copy frontend build into /app/frontend/dist
COPY --from=frontend-build /frontend/dist /app/frontend/dist

# Set PYTHONPATH so Python can find the app module
ENV PYTHONPATH=/app/backend:$PYTHONPATH

# HF Spaces uses port 7860
EXPOSE 7860

CMD ["uvicorn", "backend.app.main:app", "--host", "0.0.0.0", "--port", "7860"]