Spaces:
Sleeping
Sleeping
Commit
·
95028b2
1
Parent(s):
aec8a80
Fix: use writable cache dirs for HF/Transformers
Browse files- Dockerfile +8 -0
- app.py +17 -6
Dockerfile
CHANGED
@@ -3,6 +3,14 @@ FROM python:3.11-slim
|
|
3 |
WORKDIR /app
|
4 |
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
COPY requirements.txt .
|
7 |
RUN pip install --no-cache-dir -r requirements.txt
|
8 |
|
|
|
3 |
WORKDIR /app
|
4 |
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
|
5 |
|
6 |
+
# Writable caches for HF/Transformers inside the container
|
7 |
+
ENV HF_HOME=/tmp/hf \
|
8 |
+
TRANSFORMERS_CACHE=/tmp/transformers \
|
9 |
+
HF_DATASETS_CACHE=/tmp/hf_datasets \
|
10 |
+
HF_HUB_DISABLE_TELEMETRY=1
|
11 |
+
|
12 |
+
RUN mkdir -p /tmp/hf /tmp/transformers /tmp/hf_datasets && chmod -R 777 /tmp
|
13 |
+
|
14 |
COPY requirements.txt .
|
15 |
RUN pip install --no-cache-dir -r requirements.txt
|
16 |
|
app.py
CHANGED
@@ -3,16 +3,27 @@ from fastapi import FastAPI
|
|
3 |
from pydantic import BaseModel
|
4 |
from pathlib import Path
|
5 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
app = FastAPI(title="Incident ML Inference API")
|
8 |
|
9 |
-
LOCAL_MODEL = Path(__file__).resolve().parents[1] / "models" / "incident_classifier"
|
10 |
|
11 |
-
#
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
16 |
|
17 |
# Sentiment (keep public model for now)
|
18 |
sentiment_analyzer = pipeline("sentiment-analysis", model="cardiffnlp/twitter-xlm-roberta-base-sentiment")
|
|
|
3 |
from pydantic import BaseModel
|
4 |
from pathlib import Path
|
5 |
from transformers import pipeline
|
6 |
+
import os
|
7 |
+
|
8 |
+
# Put all caches in writable /tmp
|
9 |
+
os.environ.setdefault("HF_HOME", "/tmp/hf")
|
10 |
+
os.environ.setdefault("TRANSFORMERS_CACHE", "/tmp/transformers")
|
11 |
+
os.environ.setdefault("HF_DATASETS_CACHE", "/tmp/hf_datasets")
|
12 |
+
os.environ.setdefault("HF_HUB_DISABLE_TELEMETRY", "1")
|
13 |
+
|
14 |
|
15 |
app = FastAPI(title="Incident ML Inference API")
|
16 |
|
|
|
17 |
|
18 |
+
# LOCAL_MODEL = Path(__file__).resolve().parents[1] / "models" / "incident_classifier"
|
19 |
+
|
20 |
+
# # Category classifier (your fine-tuned model if available)
|
21 |
+
# if LOCAL_MODEL.exists():
|
22 |
+
# incident_classifier = pipeline("text-classification", model="brijeshpandya/incident-classifier")
|
23 |
+
# else:
|
24 |
+
# incident_classifier = pipeline("text-classification", model="cardiffnlp/twitter-xlm-roberta-base")
|
25 |
+
|
26 |
+
incident_classifier = pipeline("text-classification", model="brijeshpandya/incident-classifier")
|
27 |
|
28 |
# Sentiment (keep public model for now)
|
29 |
sentiment_analyzer = pipeline("sentiment-analysis", model="cardiffnlp/twitter-xlm-roberta-base-sentiment")
|