Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def classify(X):
global classifier
if not classifier:
if os.path.exists(model_path):
classifier = TextClassifier.load(model_path)
else:
logger.error(
f"Could not load model at {model_path}.\n"
f"Download model with \"underthesea download {UTSModel.tc_general.value}\".")
sys.exit(1)
sentence = Sentence(X)
classifier.predict(sentence)
labels = sentence.labels
return labels
def sentiment(text):
global classifier
if not classifier:
if os.path.exists(model_path):
classifier = TextClassifier.load(model_path)
else:
logger.error(
f"Could not load model at {model_path}.\n"
f"Download model with \"underthesea download {UTSModel.sa_bank.value}\".")
sys.exit(1)
sentence = Sentence(text)
classifier.predict(sentence)
labels = sentence.labels
return [label.value for label in labels]
def classify(X):
global classifier
if not classifier:
if os.path.exists(model_path):
classifier = TextClassifier.load(model_path)
else:
logger.error(
f"Could not load model at {model_path}.\n"
f"Download model with \"underthesea download {UTSModel.tc_bank.value}\".")
sys.exit(1)
sentence = Sentence(X)
classifier.predict(sentence)
labels = sentence.labels
if not labels:
return None
return [label.value for label in labels]
def get_model_path(model):
if model == UTSModel.tc_bank:
return Path(CACHE_ROOT) / "models" / "tc_bank"
if model == UTSModel.tc_general:
return Path(CACHE_ROOT) / "models" / "tc_general"
if model == UTSModel.sa_general:
return Path(CACHE_ROOT) / "models" / "sa_general"
if model == UTSModel.sa_bank:
return Path(CACHE_ROOT) / "models" / "sa_bank"
def get_model_path(model):
if model == UTSModel.tc_bank:
return Path(CACHE_ROOT) / "models" / "tc_bank"
if model == UTSModel.tc_general:
return Path(CACHE_ROOT) / "models" / "tc_general"
if model == UTSModel.sa_general:
return Path(CACHE_ROOT) / "models" / "sa_general"
if model == UTSModel.sa_bank:
return Path(CACHE_ROOT) / "models" / "sa_bank"
def get_model_path(model):
if model == UTSModel.tc_bank:
return Path(CACHE_ROOT) / "models" / "tc_bank"
if model == UTSModel.tc_general:
return Path(CACHE_ROOT) / "models" / "tc_general"
if model == UTSModel.sa_general:
return Path(CACHE_ROOT) / "models" / "sa_general"
if model == UTSModel.sa_bank:
return Path(CACHE_ROOT) / "models" / "sa_bank"
def get_model_path(model):
if model == UTSModel.tc_bank:
return Path(CACHE_ROOT) / "models" / "tc_bank"
if model == UTSModel.tc_general:
return Path(CACHE_ROOT) / "models" / "tc_general"
if model == UTSModel.sa_general:
return Path(CACHE_ROOT) / "models" / "sa_general"
if model == UTSModel.sa_bank:
return Path(CACHE_ROOT) / "models" / "sa_bank"