Spaces:
Sleeping
Sleeping
FairValue commited on
Commit ·
1f734ca
1
Parent(s): b72652e
feat: add Dockerfile for HuggingFace Spaces deployment + fix path resolution for Docker
Browse files- Dockerfile +25 -0
- api/main.py +8 -4
Dockerfile
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11-slim
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
# Install OS dependencies
|
| 6 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 7 |
+
build-essential \
|
| 8 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 9 |
+
|
| 10 |
+
# Install Python dependencies first (Docker cache layer)
|
| 11 |
+
COPY requirements.txt .
|
| 12 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 13 |
+
|
| 14 |
+
# Copy only what the API needs at runtime
|
| 15 |
+
# (raw CSVs are gitignored and NOT copied — only the processed outputs)
|
| 16 |
+
COPY api/ ./api/
|
| 17 |
+
COPY src/ ./src/
|
| 18 |
+
COPY fairvalue_xgboost.json .
|
| 19 |
+
COPY data/processed/app_features.csv ./data/processed/app_features.csv
|
| 20 |
+
|
| 21 |
+
# Hugging Face Spaces requires port 7860
|
| 22 |
+
EXPOSE 7860
|
| 23 |
+
|
| 24 |
+
# Uvicorn with 2 workers for concurrent requests
|
| 25 |
+
CMD ["uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "2"]
|
api/main.py
CHANGED
|
@@ -77,13 +77,17 @@ async def scout_player(player: str, club: str = "", interested_club: str = ""):
|
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
-
# ── Currency Config ───────────────────────────────────────────────────────────
|
| 81 |
EUR_TO_GBP = 0.85 # Approximate — review quarterly
|
| 82 |
|
| 83 |
-
# ──
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
| 86 |
|
|
|
|
| 87 |
df_global = None
|
| 88 |
model_global = None
|
| 89 |
expected_cols_global = None
|
|
|
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
+
# ── Currency Config ────────────────────────────────────────────────────────────
|
| 81 |
EUR_TO_GBP = 0.85 # Approximate — review quarterly
|
| 82 |
|
| 83 |
+
# ── Path resolution: works locally AND inside the Docker container ─────────────
|
| 84 |
+
# Using __file__ means paths are always relative to api/main.py, not cwd.
|
| 85 |
+
import pathlib
|
| 86 |
+
_ROOT = pathlib.Path(__file__).parent.parent.resolve()
|
| 87 |
+
DATA_PATH = str(_ROOT / "data" / "processed" / "app_features.csv")
|
| 88 |
+
MODEL_PATH = str(_ROOT / "fairvalue_xgboost.json")
|
| 89 |
|
| 90 |
+
# ── Data / Model Globals ───────────────────────────────────────────────────────
|
| 91 |
df_global = None
|
| 92 |
model_global = None
|
| 93 |
expected_cols_global = None
|