Spaces:
Sleeping
Sleeping
Hardik commited on
Commit ·
374f547
1
Parent(s): 46042a6
Revert sklearn to 1.5.1, fix multi_class at load time
Browse files- Dockerfile +1 -1
- ml_service/app/services/model_loader.py +9 -2
- ml_service/requirements.txt +1 -1
Dockerfile
CHANGED
|
@@ -6,7 +6,7 @@ RUN apt-get update && apt-get install -y curl nginx supervisor && \
|
|
| 6 |
apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 7 |
|
| 8 |
RUN pip install --no-cache-dir fastapi==0.111.0 uvicorn==0.30.1 pydantic==2.7.4 \
|
| 9 |
-
pydantic-settings==2.3.4 numpy==1.26.4 pandas==2.2.2 scikit-learn==1.
|
| 10 |
scipy==1.13.1 nltk==3.8.1 tensorflow==2.16.1 keras==3.3.3 \
|
| 11 |
transformers==4.41.2 joblib==1.4.2 && \
|
| 12 |
pip install --no-cache-dir torch==2.3.1 --index-url https://download.pytorch.org/whl/cpu
|
|
|
|
| 6 |
apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 7 |
|
| 8 |
RUN pip install --no-cache-dir fastapi==0.111.0 uvicorn==0.30.1 pydantic==2.7.4 \
|
| 9 |
+
pydantic-settings==2.3.4 numpy==1.26.4 pandas==2.2.2 scikit-learn==1.5.1 \
|
| 10 |
scipy==1.13.1 nltk==3.8.1 tensorflow==2.16.1 keras==3.3.3 \
|
| 11 |
transformers==4.41.2 joblib==1.4.2 && \
|
| 12 |
pip install --no-cache-dir torch==2.3.1 --index-url https://download.pytorch.org/whl/cpu
|
ml_service/app/services/model_loader.py
CHANGED
|
@@ -85,8 +85,15 @@ class ModelManager:
|
|
| 85 |
vec_path = os.path.join(settings.MODELS_ML_DIR, "tfidf_vectorizer.pkl")
|
| 86 |
model_path = os.path.join(settings.MODELS_ML_DIR, "sentiment_model.pkl")
|
| 87 |
if os.path.exists(vec_path) and os.path.exists(model_path):
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
self.models_loaded["logistic_regression"] = True
|
| 91 |
except Exception as e:
|
| 92 |
self.load_errors["lr"] = str(e)
|
|
|
|
| 85 |
vec_path = os.path.join(settings.MODELS_ML_DIR, "tfidf_vectorizer.pkl")
|
| 86 |
model_path = os.path.join(settings.MODELS_ML_DIR, "sentiment_model.pkl")
|
| 87 |
if os.path.exists(vec_path) and os.path.exists(model_path):
|
| 88 |
+
import sklearn
|
| 89 |
+
if tuple(int(x) for x in sklearn.__version__.split(".")[:2]) >= (1, 4):
|
| 90 |
+
self.lr_vectorizer = joblib.load(vec_path)
|
| 91 |
+
self.lr_model = joblib.load(model_path)
|
| 92 |
+
if not hasattr(self.lr_model, "multi_class"):
|
| 93 |
+
self.lr_model.multi_class = "ovr"
|
| 94 |
+
else:
|
| 95 |
+
self.lr_vectorizer = joblib.load(vec_path)
|
| 96 |
+
self.lr_model = joblib.load(model_path)
|
| 97 |
self.models_loaded["logistic_regression"] = True
|
| 98 |
except Exception as e:
|
| 99 |
self.load_errors["lr"] = str(e)
|
ml_service/requirements.txt
CHANGED
|
@@ -4,7 +4,7 @@ pydantic==2.7.4
|
|
| 4 |
pydantic-settings==2.3.4
|
| 5 |
numpy==1.26.4
|
| 6 |
pandas==2.2.2
|
| 7 |
-
scikit-learn==1.
|
| 8 |
scipy==1.13.1
|
| 9 |
nltk==3.8.1
|
| 10 |
tensorflow==2.16.1
|
|
|
|
| 4 |
pydantic-settings==2.3.4
|
| 5 |
numpy==1.26.4
|
| 6 |
pandas==2.2.2
|
| 7 |
+
scikit-learn==1.5.1
|
| 8 |
scipy==1.13.1
|
| 9 |
nltk==3.8.1
|
| 10 |
tensorflow==2.16.1
|