Spaces:
Sleeping
Sleeping
Update appStore/vulnerability_analysis.py
Browse files
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 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
with col2:
|
| 114 |
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
|
| 120 |
-
|
| 121 |
-
|
| 122 |
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
-
#
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
# Update the count in the dictionary
|
| 130 |
-
group_counts[sublist] = group_counts.get(sublist, 0) + 1
|
| 131 |
|
| 132 |
-
|
| 133 |
-
|
| 134 |
|
| 135 |
-
|
| 136 |
-
|
| 137 |
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
|
|
|
| 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)
|