File size: 1,513 Bytes
a77d489
896a559
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a77d489
896a559
 
 
a77d489
 
896a559
 
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

# Product Attribute Extraction API - Docker image
# Compatible with Hugging Face Docker Spaces (port 7860, non-root user)
# and with plain local `docker run` / docker-compose.
FROM python:3.12-slim

# HF Spaces containers run as a non-root user; create one matching their
# convention (uid 1000) so file permissions work whether this builds on
# HF Spaces or locally.
RUN useradd -m -u 1000 user
WORKDIR /app

# System deps kept minimal; scikit-learn wheels are pure-python/precompiled
# so no build-essential is needed on slim.
COPY --chown=user requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy project
COPY --chown=user data/ ./data/
COPY --chown=user src/ ./src/
COPY --chown=user app.py .

USER user

# Build the labeled dataset and train the model at image build time, so the
# container starts up with a ready-to-serve model.joblib baked in (no
# training step needed at runtime/startup).
RUN cd data && python3 build_dataset.py && cd ../src && python3 train.py

# Hugging Face Docker Spaces require the app to listen on port 7860.
EXPOSE 7860

# Basic container healthcheck against the /health endpoint.
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
  CMD python3 -c "import urllib.request; urllib.request.urlopen('http://localhost:7860/health')" || exit 1

# app.py at the repo root is the entrypoint (HF Spaces convention); it
# wires up the extraction pipeline living in src/.
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]