leavoigt commited on
Commit
d6606ef
1 Parent(s): 4722147

Update appStore/vulnerability_analysis.py

Browse files
Files changed (1) hide show
  1. appStore/vulnerability_analysis.py +66 -0
appStore/vulnerability_analysis.py CHANGED
@@ -74,4 +74,70 @@ def app():
74
  st.session_state.key1 = df
75
 
76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
 
74
  st.session_state.key1 = df
75
 
76
 
77
+ def vulnerability_display():
78
+
79
+ # Assign dataframe a name
80
+ df_vul = st.session_state['key0']
81
+ st.write(df_vul)
82
+
83
+ col1, col2 = st.columns([1,1])
84
+
85
+ with col1:
86
+
87
+ # Header
88
+ st.subheader("Explore references to vulnerable groups:")
89
+
90
+ # Text
91
+ num_paragraphs = len(df_vul['Vulnerability Label'])
92
+ num_references = df_vul['Vulnerability Label'].apply(lambda x: 'Other' not in x).sum()
93
+
94
+ st.markdown(f"""<div style="text-align: justify;"> The document contains a
95
+ total of <span style="color: red;">{num_paragraphs}</span> paragraphs.
96
+ We identified <span style="color: red;">{num_references}</span>
97
+ references to vulnerable groups.</div>
98
+ <br>
99
+ In the pie chart on the right you can see the distribution of the different
100
+ groups defined. For a more detailed view in the text, see the paragraphs and
101
+ their respective labels in the table below.</div>""", unsafe_allow_html=True)
102
+
103
+ with col2:
104
+
105
+ ### Bar chart
106
+
107
+ # # Create a df that stores all the labels
108
+ df_labels = pd.DataFrame(list(label_dict.items()), columns=['Label ID', 'Label'])
109
+
110
+ # Count how often each label appears in the "Vulnerability Labels" column
111
+ group_counts = {}
112
+
113
+ # Iterate through each sublist
114
+ for index, row in df_vul.iterrows():
115
+
116
+ # Iterate through each group in the sublist
117
+ for sublist in row['Vulnerability Label']:
118
+
119
+ # Update the count in the dictionary
120
+ group_counts[sublist] = group_counts.get(sublist, 0) + 1
121
+
122
+ # Create a new dataframe from group_counts
123
+ df_label_count = pd.DataFrame(list(group_counts.items()), columns=['Label', 'Count'])
124
+
125
+ # Merge the label counts with the df_label DataFrame
126
+ df_label_count = df_labels.merge(df_label_count, on='Label', how='left')
127
+ st.write("df_label_count")
128
+
129
+ # # Configure graph
130
+ # fig = px.pie(df_labels,
131
+ # names="Label",
132
+ # values="Count",
133
+ # title='Label Counts',
134
+ # hover_name="Count",
135
+ # color_discrete_sequence=px.colors.qualitative.Plotly
136
+ # )
137
+
138
+ # #Show plot
139
+ # st.plotly_chart(fig, use_container_width=True)
140
+
141
+ # ### Table
142
+ st.table(df_vul[df_vul['Vulnerability Label'] != 'Other'])
143