Skip to content

Commit

Permalink
small fixes for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
ialbert committed Sep 21, 2021
1 parent 46f86d7 commit dcf24e4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
19 changes: 14 additions & 5 deletions biostar/utils/spamlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,20 @@

import plac
from joblib import dump, load
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.metrics import classification_report
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import MultinomialNB
from sklearn.pipeline import make_pipeline

logger = logging.getLogger("engine")

try:
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.metrics import classification_report
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import MultinomialNB
from sklearn.pipeline import make_pipeline
has_sklearn = True
except ImportError as exc:
logger.error("sklearn not installed, no predictions are generated")
has_sklearn = False

def load_model(model="spam.model"):
nb = load(model)
return nb
Expand All @@ -38,6 +44,9 @@ def classify_content(content, model):
"""
Classify content
"""
if not has_sklearn:
return 0

try:
nb = load_model(model)
y_pred = nb.predict([content])
Expand Down
3 changes: 2 additions & 1 deletion conf/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ Whoosh==2.7.4
zipp==3.4.0
plac
pymemcache
bs4
joblib
bs4

0 comments on commit dcf24e4

Please sign in to comment.