leavoigt commited on
Commit
84d8591
·
verified ·
1 Parent(s): 2d334e2

Update utils/vulnerability_classifier.py

Browse files
Files changed (1) hide show
  1. utils/vulnerability_classifier.py +6 -16
utils/vulnerability_classifier.py CHANGED
@@ -8,6 +8,7 @@ from utils.preprocessing import processingpipeline
8
  import streamlit as st
9
  from transformers import pipeline
10
  from setfit import SetFitModel
 
11
 
12
 
13
  # labels dictionary
@@ -76,25 +77,14 @@ def load_vulnerabilityClassifier(config_file:str = None, classifier_name:str = N
76
  classifier_name = config.get('vulnerability','MODEL')
77
 
78
  logging.info("Loading vulnerability classifier")
79
-
80
- # we are using the pipeline as the model is multilabel and DocumentClassifier
81
- # from Haystack doesnt support multilabel
82
- # in pipeline we use 'sigmoid' to explicitly tell pipeline to make it multilabel
83
- # if not then it will automatically use softmax, which is not a desired thing.
84
- # doc_classifier = TransformersDocumentClassifier(
85
- # model_name_or_path=classifier_name,
86
- # task="text-classification",
87
- # top_k = None)
88
 
89
- # Download model from HF Hub
90
- doc_classifier = SetFitModel.from_pretrained(classifier_name)
 
91
 
 
 
92
 
93
- # doc_classifier = pipeline("text-classification",
94
- # model=classifier_name,
95
- # return_all_scores=True,
96
- # function_to_apply= "sigmoid")
97
-
98
  return doc_classifier
99
 
100
 
 
8
  import streamlit as st
9
  from transformers import pipeline
10
  from setfit import SetFitModel
11
+ import os
12
 
13
 
14
  # labels dictionary
 
77
  classifier_name = config.get('vulnerability','MODEL')
78
 
79
  logging.info("Loading vulnerability classifier")
 
 
 
 
 
 
 
 
 
80
 
81
+
82
+ # Get token from environment variable
83
+ hf_token = os.environ["model_token"]
84
 
85
+ # Download model from HF Hub
86
+ doc_classifier = SetFitModel.from_pretrained(classifier_name, model_token=hf_token)
87
 
 
 
 
 
 
88
  return doc_classifier
89
 
90