leavoigt commited on
Commit
2604e77
1 Parent(s): 0919f9a

Update utils/vulnerability_classifier.py

Browse files
Files changed (1) hide show
  1. utils/vulnerability_classifier.py +21 -19
utils/vulnerability_classifier.py CHANGED
@@ -84,24 +84,26 @@ def vulnerability_classification(haystack_doc:pd.DataFrame,
84
  classifier_model = st.session_state['vulnerability_classifier']
85
 
86
  predictions = classifier_model(list(haystack_doc.text))
87
-
88
- list_ = []
89
- for i in range(len(predictions)):
90
 
91
- temp = predictions[i]
92
- placeholder = {}
93
- for j in range(len(temp)):
94
- placeholder[temp[j]['label']] = temp[j]['score']
95
- list_.append(placeholder)
96
- labels_ = [{**list_[l]} for l in range(len(predictions))]
97
- truth_df = DataFrame.from_dict(labels_)
98
- truth_df = truth_df.round(2)
99
- truth_df = truth_df.astype(float) >= threshold
100
- truth_df = truth_df.astype(str)
101
- categories = list(truth_df.columns)
102
- truth_df['Vulnerability Label'] = truth_df.apply(lambda x: {i if x[i]=='True' else
103
- None for i in categories}, axis=1)
104
- truth_df['Vulnerability Label'] = truth_df.apply(lambda x: list(x['Vulnerability Label']
105
- -{None}),axis=1)
106
- haystack_doc['Vulnerability Label'] = list(truth_df['Vulnerability Label'])
 
 
 
 
 
107
  return haystack_doc
 
84
  classifier_model = st.session_state['vulnerability_classifier']
85
 
86
  predictions = classifier_model(list(haystack_doc.text))
 
 
 
87
 
88
+ haystack_doc['Vulnerability Label'] = predictions
89
+
90
+ # list_ = []
91
+ # for i in range(len(predictions)):
92
+
93
+ # temp = predictions[i]
94
+ # placeholder = {}
95
+ # for j in range(len(temp)):
96
+ # placeholder[temp[j]['label']] = temp[j]['score']
97
+ # list_.append(placeholder)
98
+ # labels_ = [{**list_[l]} for l in range(len(predictions))]
99
+ # truth_df = DataFrame.from_dict(labels_)
100
+ # truth_df = truth_df.round(2)
101
+ # truth_df = truth_df.astype(float) >= threshold
102
+ # truth_df = truth_df.astype(str)
103
+ # categories = list(truth_df.columns)
104
+ # truth_df['Vulnerability Label'] = truth_df.apply(lambda x: {i if x[i]=='True' else
105
+ # None for i in categories}, axis=1)
106
+ # truth_df['Vulnerability Label'] = truth_df.apply(lambda x: list(x['Vulnerability Label']
107
+ # -{None}),axis=1)
108
+ # haystack_doc['Vulnerability Label'] = list(truth_df['Vulnerability Label'])
109
  return haystack_doc