leavoigt commited on
Commit
b9a3332
1 Parent(s): 01c57c0

Update appStore/vulnerability_analysis.py

Browse files
Files changed (1) hide show
  1. appStore/vulnerability_analysis.py +55 -60
appStore/vulnerability_analysis.py CHANGED
@@ -91,72 +91,67 @@ def vulnerability_display():
91
 
92
  # Header
93
  st.subheader("Explore references to vulnerable groups:")
94
-
95
- col1, col2 = st.columns([1,1])
96
-
97
- with col1:
98
 
99
 
100
- # Text
101
- num_paragraphs = len(df['Vulnerability Label'])
102
- num_references = len(df_filtered['Group(s)'])
103
-
104
- st.markdown(f"""<div style="text-align: justify;"> The document contains a
105
- total of <span style="color: red;">{num_paragraphs}</span> paragraphs.
106
- We identified <span style="color: red;">{num_references}</span>
107
- references to groups in vulnerable situations.</div>
108
- <br>
109
- In the chart on the right you can see how often each group has been referenced.
110
- For a more detailed view in the text, see the paragraphs and
111
- their respective labels in the table below.</div>""", unsafe_allow_html=True)
112
-
113
- with col2:
114
 
115
- ### Bar chart
116
-
117
- # # Create a df that stores all the labels
118
- df_labels = pd.DataFrame(list(label_dict.items()), columns=['Label ID', 'Label'])
119
 
120
- # Count how often each label appears in the "Group identified" column
121
- group_counts = {}
122
 
123
- # Iterate through each sublist
124
- for index, row in df_filtered.iterrows():
 
 
 
125
 
126
- # Iterate through each group in the sublist
127
- for sublist in row['Group(s)']:
128
-
129
- # Update the count in the dictionary
130
- group_counts[sublist] = group_counts.get(sublist, 0) + 1
131
 
132
- # Create a new dataframe from group_counts
133
- df_label_count = pd.DataFrame(list(group_counts.items()), columns=['Label', 'Count'])
134
 
135
- # Merge the label counts with the df_label DataFrame
136
- df_label_count = df_labels.merge(df_label_count, on='Label', how='left')
137
 
138
- # Exclude the "Other" group
139
- df_bar_chart = df_label_count[df_label_count['Label'] != 'Other']
140
-
141
- # Bar chart
142
- fig = go.Figure()
143
-
144
- fig.add_trace(go.Bar(
145
- y=df_bar_chart.Label,
146
- x=df_bar_chart.Count,
147
- orientation='h',
148
- marker=dict(color='purple'),
149
- ))
150
-
151
- # Customize layout
152
- fig.update_layout(
153
- title='Number of references to each group',
154
- xaxis_title='Number of references',
155
- yaxis_title='Group',
156
- )
157
-
158
- # Show the plot
159
- #fig.show()
160
-
161
- #Show plot
162
- st.plotly_chart(fig, use_container_width=True)
 
91
 
92
  # Header
93
  st.subheader("Explore references to vulnerable groups:")
 
 
 
 
94
 
95
 
96
+ # Text
97
+ num_paragraphs = len(df['Vulnerability Label'])
98
+ num_references = len(df_filtered['Group(s)'])
99
+
100
+ st.markdown(f"""<div style="text-align: justify;"> The document contains a
101
+ total of <span style="color: red;">{num_paragraphs}</span> paragraphs.
102
+ We identified <span style="color: red;">{num_references}</span>
103
+ references to groups in vulnerable situations.</div>
104
+ <br>
105
+ In the chart on the right you can see how often each group has been referenced.
106
+ For a more detailed view in the text, see the paragraphs and
107
+ their respective labels in the table below.</div>""", unsafe_allow_html=True)
108
+
 
109
 
110
+ ### Bar chart
111
+
112
+ # # Create a df that stores all the labels
113
+ df_labels = pd.DataFrame(list(label_dict.items()), columns=['Label ID', 'Label'])
114
 
115
+ # Count how often each label appears in the "Group identified" column
116
+ group_counts = {}
117
 
118
+ # Iterate through each sublist
119
+ for index, row in df_filtered.iterrows():
120
+
121
+ # Iterate through each group in the sublist
122
+ for sublist in row['Group(s)']:
123
 
124
+ # Update the count in the dictionary
125
+ group_counts[sublist] = group_counts.get(sublist, 0) + 1
 
 
 
126
 
127
+ # Create a new dataframe from group_counts
128
+ df_label_count = pd.DataFrame(list(group_counts.items()), columns=['Label', 'Count'])
129
 
130
+ # Merge the label counts with the df_label DataFrame
131
+ df_label_count = df_labels.merge(df_label_count, on='Label', how='left')
132
 
133
+ # Exclude the "Other" group
134
+ df_bar_chart = df_label_count[df_label_count['Label'] != 'Other']
135
+
136
+ # Bar chart
137
+ fig = go.Figure()
138
+
139
+ fig.add_trace(go.Bar(
140
+ y=df_bar_chart.Label,
141
+ x=df_bar_chart.Count,
142
+ orientation='h',
143
+ marker=dict(color='purple'),
144
+ ))
145
+
146
+ # Customize layout
147
+ fig.update_layout(
148
+ title='Number of references to each group',
149
+ xaxis_title='Number of references',
150
+ yaxis_title='Group',
151
+ )
152
+
153
+ # Show the plot
154
+ #fig.show()
155
+
156
+ #Show plot
157
+ st.plotly_chart(fig, use_container_width=True)