Commit ·
856694c
1
Parent(s): e84af31
fixing errors
Browse files- __pycache__/app.cpython-312.pyc +0 -0
- app.py +34 -8
__pycache__/app.cpython-312.pyc
CHANGED
|
Binary files a/__pycache__/app.cpython-312.pyc and b/__pycache__/app.cpython-312.pyc differ
|
|
|
app.py
CHANGED
|
@@ -4,34 +4,60 @@ import numpy as np
|
|
| 4 |
|
| 5 |
from intent import predict_intent
|
| 6 |
from topic_model import get_review_topic
|
| 7 |
-
import download_models
|
| 8 |
from huggingface_hub import hf_hub_download
|
| 9 |
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
pipeline_file = hf_hub_download(
|
| 13 |
repo_id="Maarij-Aqeel/Customer_review_analyzer",
|
| 14 |
filename="sentiment_pipeline.pkl"
|
| 15 |
)
|
| 16 |
-
|
| 17 |
repo_id="Maarij-Aqeel/Customer_review_analyzer",
|
| 18 |
filename="tfidf_vectorizer.pkl"
|
| 19 |
)
|
| 20 |
-
|
| 21 |
repo_id="Maarij-Aqeel/Customer_review_analyzer",
|
| 22 |
filename="nmf_model.pkl"
|
| 23 |
)
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
try:
|
| 28 |
sentiment_pipeline = joblib.load(pipeline_file)
|
| 29 |
except Exception as e: # pragma: no cover - helpful when learning
|
| 30 |
raise RuntimeError("could not load sentiment pipeline: %s" % e)
|
| 31 |
|
| 32 |
try:
|
| 33 |
-
vectorizer = joblib.load(
|
| 34 |
-
nmf_model = joblib.load(
|
| 35 |
except Exception as e:
|
| 36 |
raise RuntimeError("could not load vectorizer/nmf model: %s" % e)
|
| 37 |
|
|
|
|
| 4 |
|
| 5 |
from intent import predict_intent
|
| 6 |
from topic_model import get_review_topic
|
|
|
|
| 7 |
from huggingface_hub import hf_hub_download
|
| 8 |
|
| 9 |
|
| 10 |
+
class TextPreprocessor:
|
| 11 |
+
"""Stub class to mimic the preprocessing step used when training.
|
| 12 |
+
|
| 13 |
+
The original pipeline was pickled with this class defined in ``__main__``
|
| 14 |
+
(a notebook). When the module is imported on HuggingFace the class lives in
|
| 15 |
+
``app`` instead, so unpickling fails unless we make a dummy version
|
| 16 |
+
available under the old name.
|
| 17 |
+
"""
|
| 18 |
+
def __init__(self):
|
| 19 |
+
pass
|
| 20 |
+
|
| 21 |
+
def fit(self, X, y=None):
|
| 22 |
+
return self
|
| 23 |
+
|
| 24 |
+
def transform(self, X):
|
| 25 |
+
return X
|
| 26 |
+
|
| 27 |
+
def fit_transform(self, X, y=None):
|
| 28 |
+
return X
|
| 29 |
+
|
| 30 |
+
def __call__(self, x):
|
| 31 |
+
return x
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
# register stub in __main__ so joblib can resolve the name during unpickling
|
| 35 |
+
import __main__
|
| 36 |
+
__main__.TextPreprocessor = TextPreprocessor
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
# download sentiment pipeline and other assets from the space repo
|
| 40 |
pipeline_file = hf_hub_download(
|
| 41 |
repo_id="Maarij-Aqeel/Customer_review_analyzer",
|
| 42 |
filename="sentiment_pipeline.pkl"
|
| 43 |
)
|
| 44 |
+
vectorizer_file = hf_hub_download(
|
| 45 |
repo_id="Maarij-Aqeel/Customer_review_analyzer",
|
| 46 |
filename="tfidf_vectorizer.pkl"
|
| 47 |
)
|
| 48 |
+
nmf_file = hf_hub_download(
|
| 49 |
repo_id="Maarij-Aqeel/Customer_review_analyzer",
|
| 50 |
filename="nmf_model.pkl"
|
| 51 |
)
|
| 52 |
|
|
|
|
|
|
|
| 53 |
try:
|
| 54 |
sentiment_pipeline = joblib.load(pipeline_file)
|
| 55 |
except Exception as e: # pragma: no cover - helpful when learning
|
| 56 |
raise RuntimeError("could not load sentiment pipeline: %s" % e)
|
| 57 |
|
| 58 |
try:
|
| 59 |
+
vectorizer = joblib.load(vectorizer_file)
|
| 60 |
+
nmf_model = joblib.load(nmf_file)
|
| 61 |
except Exception as e:
|
| 62 |
raise RuntimeError("could not load vectorizer/nmf model: %s" % e)
|
| 63 |
|