Spaces:
Sleeping
Sleeping
Seth commited on
Commit ·
5913b23
1
Parent(s): f6e574f
Fix Dockerfile and add model preloading for HF Spaces
Browse files- Dockerfile +1 -1
- backend/app/main.py +11 -0
Dockerfile
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
# ---------- build frontend ----------
|
| 2 |
FROM node:20-bookworm AS frontend-build
|
| 3 |
WORKDIR /frontend
|
| 4 |
-
COPY frontend/package.json
|
| 5 |
RUN npm install
|
| 6 |
COPY frontend/ .
|
| 7 |
RUN npm run build
|
|
|
|
| 1 |
# ---------- build frontend ----------
|
| 2 |
FROM node:20-bookworm AS frontend-build
|
| 3 |
WORKDIR /frontend
|
| 4 |
+
COPY frontend/package.json ./
|
| 5 |
RUN npm install
|
| 6 |
COPY frontend/ .
|
| 7 |
RUN npm run build
|
backend/app/main.py
CHANGED
|
@@ -26,6 +26,17 @@ def get_classifier_instance():
|
|
| 26 |
classifier = get_classifier()
|
| 27 |
return classifier
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
# ---- API ----
|
| 30 |
@app.get("/api/health")
|
| 31 |
def health():
|
|
|
|
| 26 |
classifier = get_classifier()
|
| 27 |
return classifier
|
| 28 |
|
| 29 |
+
@app.on_event("startup")
|
| 30 |
+
async def startup_event():
|
| 31 |
+
"""Preload the classifier on startup to avoid first-request delay."""
|
| 32 |
+
print("Preloading classifier on startup...")
|
| 33 |
+
try:
|
| 34 |
+
get_classifier_instance()
|
| 35 |
+
print("✅ Classifier loaded and ready!")
|
| 36 |
+
except Exception as e:
|
| 37 |
+
print(f"⚠️ Warning: Could not preload classifier: {e}")
|
| 38 |
+
print("Classifier will be loaded on first request.")
|
| 39 |
+
|
| 40 |
# ---- API ----
|
| 41 |
@app.get("/api/health")
|
| 42 |
def health():
|