leavoigt commited on
Commit
f938459
1 Parent(s): 4ddab6b

Update appStore/vulnerability_analysis.py

Browse files
Files changed (1) hide show
  1. appStore/vulnerability_analysis.py +14 -20
appStore/vulnerability_analysis.py CHANGED
@@ -72,23 +72,21 @@ def app():
72
  df = vulnerability_classification(haystack_doc=df,
73
  threshold= params['threshold'])
74
 
75
- # Filter the dataframe to only show the paragraphs with references
76
- df_filtered = df[df['Vulnerability Label'].apply(lambda x: len(x) > 0 and 'Other' not in x)]
77
-
78
- # Rename column
79
- df_filtered.rename(columns={'Vulnerability Label': 'Group identified'}, inplace=True)
80
-
81
 
82
  # Store df in session state with key1
83
- st.session_state.key1 = df_filtered
84
 
85
 
86
  def vulnerability_display():
87
 
88
- # Assign dataframe a name
89
- df_vul = st.session_state['key0']
90
 
91
- #st.write(df_vul)
 
 
 
 
92
 
93
  # Header
94
  st.subheader("Explore references to vulnerable groups:")
@@ -99,8 +97,8 @@ def vulnerability_display():
99
 
100
 
101
  # Text
102
- num_paragraphs = len(df_vul['Vulnerability Label'])
103
- num_references = df_vul['Vulnerability Label'].apply(lambda x: 'Other' not in x).sum()
104
 
105
  st.markdown(f"""<div style="text-align: justify;"> The document contains a
106
  total of <span style="color: red;">{num_paragraphs}</span> paragraphs.
@@ -118,14 +116,14 @@ def vulnerability_display():
118
  # # Create a df that stores all the labels
119
  df_labels = pd.DataFrame(list(label_dict.items()), columns=['Label ID', 'Label'])
120
 
121
- # Count how often each label appears in the "Vulnerability Labels" column
122
  group_counts = {}
123
 
124
  # Iterate through each sublist
125
- for index, row in df_vul.iterrows():
126
 
127
  # Iterate through each group in the sublist
128
- for sublist in row['Vulnerability Label']:
129
 
130
  # Update the count in the dictionary
131
  group_counts[sublist] = group_counts.get(sublist, 0) + 1
@@ -147,8 +145,4 @@ def vulnerability_display():
147
  labels={'Count': 'Frequency'})
148
 
149
  #Show plot
150
- st.plotly_chart(fig, use_container_width=True)
151
-
152
- # ### Table
153
- #st.write(df_vul[df_vul['Vulnerability Label'].apply(lambda x: 'Other' not in x)])
154
-
 
72
  df = vulnerability_classification(haystack_doc=df,
73
  threshold= params['threshold'])
74
 
 
 
 
 
 
 
75
 
76
  # Store df in session state with key1
77
+ st.session_state.key1 = df
78
 
79
 
80
  def vulnerability_display():
81
 
82
+ # Get the vulnerability df
83
+ df = st.session_state['key1']
84
 
85
+ # Filter the dataframe to only show the paragraphs with references
86
+ df_filtered = df[df['Vulnerability Label'].apply(lambda x: len(x) > 0 and 'Other' not in x)]
87
+
88
+ # Rename column
89
+ df_filtered.rename(columns={'Vulnerability Label': 'Group(s)'}, inplace=True)
90
 
91
  # Header
92
  st.subheader("Explore references to vulnerable groups:")
 
97
 
98
 
99
  # Text
100
+ num_paragraphs = len(df['Vulnerability Label'])
101
+ num_references = len(df_filtered['Group(s)'])
102
 
103
  st.markdown(f"""<div style="text-align: justify;"> The document contains a
104
  total of <span style="color: red;">{num_paragraphs}</span> paragraphs.
 
116
  # # Create a df that stores all the labels
117
  df_labels = pd.DataFrame(list(label_dict.items()), columns=['Label ID', 'Label'])
118
 
119
+ # Count how often each label appears in the "Group identified" column
120
  group_counts = {}
121
 
122
  # Iterate through each sublist
123
+ for index, row in df_filtered.iterrows():
124
 
125
  # Iterate through each group in the sublist
126
+ for sublist in row['Group(s)']:
127
 
128
  # Update the count in the dictionary
129
  group_counts[sublist] = group_counts.get(sublist, 0) + 1
 
145
  labels={'Count': 'Frequency'})
146
 
147
  #Show plot
148
+ st.plotly_chart(fig, use_container_width=True)