File size: 1,843 Bytes
8aadaef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# ── Stage 1: Build Vue frontend ──────────────────────────────────────────────
FROM node:20-alpine AS frontend-build
WORKDIR /frontend
RUN apk add --no-cache git
RUN git clone https://github.com/ICA-PUC/chatbot-norm-frontend.git .
RUN npm ci && npm run build

# ── Stage 2: Python backend ───────────────────────────────────────────────────
FROM python:3.11-slim

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

WORKDIR /app

RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    && rm -rf /var/lib/apt/lists/*

COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r requirements.txt && \
    pip install --no-cache-dir huggingface_hub

COPY . .

# Descargar el Γ­ndice FAISS desde HF Dataset
# El token HF_TOKEN se inyecta como build-arg para repos privados.
# Si el dataset es pΓΊblico, omitir --build-arg HF_TOKEN.
ARG HF_TOKEN
RUN mkdir -p data/index/intfloat/multilingual-e5-large && \
    python - <<'EOF'
import os
from huggingface_hub import hf_hub_download

token = os.getenv("HF_TOKEN") or None
repo = "ICA-PUC/norm-index"
dest = "data/index/intfloat/multilingual-e5-large"

for filename in ["faiss.index", "metadata.jsonl"]:
    path = hf_hub_download(
        repo_id=repo,
        filename=filename,
        repo_type="dataset",
        token=token,
        local_dir=dest,
    )
    print(f"Downloaded: {path}")
EOF

# Copiar el build del frontend
COPY --from=frontend-build /frontend/dist /app/static

# Puerto requerido por Hugging Face Spaces
ENV PORT=7860
EXPOSE 7860

CMD uvicorn app.main:app --host 0.0.0.0 --port ${PORT}