|
import appStore.vulnerability_analysis as vulnerability_analysis |
|
import appStore.doc_processing as processing |
|
from utils.uploadAndExample import add_upload |
|
import streamlit as st |
|
from utils.vulnerability_classifier import label_dict |
|
import pandas as pd |
|
import plotly.express as px |
|
|
|
st.set_page_config(page_title = 'Vulnerability Analysis', |
|
initial_sidebar_state='expanded', layout="wide") |
|
|
|
with st.sidebar: |
|
|
|
choice = st.sidebar.radio(label = 'Select the Document', |
|
help = 'You can upload the document \ |
|
or else you can try a example document', |
|
options = ('Upload Document', 'Try Example'), |
|
horizontal = True) |
|
add_upload(choice) |
|
|
|
with st.container(): |
|
st.markdown("<h2 style='text-align: center; color: black;'> Vulnerability Analysis </h2>", unsafe_allow_html=True) |
|
st.write(' ') |
|
|
|
with st.expander("ℹ️ - About this app", expanded=False): |
|
st.write( |
|
""" |
|
The Vulnerability Analysis App is an open-source\ |
|
digital tool which aims to assist policy analysts and \ |
|
other users in extracting and filtering references \ |
|
to different vulnerable groups from public documents. |
|
""") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
st.write(""" |
|
What Happens in background? |
|
|
|
- Step 1: Once the document is provided to app, it undergoes *Pre-processing*.\ |
|
In this step the document is broken into smaller paragraphs \ |
|
(based on word/sentence count). |
|
- Step 2: The paragraphs are then fed to the **Vulnerability Classifier** which detects if |
|
the paragraph contains any references to vulnerable groups. |
|
""") |
|
|
|
st.write("") |
|
|
|
|
|
apps = [processing.app, vulnerability_analysis.app] |
|
|
|
multiplier_val =1/len(apps) |
|
if st.button("Analyze Document"): |
|
prg = st.progress(0.0) |
|
for i,func in enumerate(apps): |
|
func() |
|
prg.progress((i+1)*multiplier_val) |
|
|
|
|
|
if 'key0' in st.session_state: |
|
with st.sidebar: |
|
topic = st.radio( |
|
"Which category you want to explore?", |
|
(['Vulnerability'])) |
|
|
|
if topic == 'Vulnerability': |
|
|
|
|
|
df_vul = st.session_state['key0'] |
|
|
|
col1, col2 = st.columns([1,1]) |
|
|
|
with col1: |
|
|
|
st.subheader("Explore references to vulnerable groups:") |
|
|
|
|
|
num_paragraphs = len(df_vul['Vulnerability Label']) |
|
num_references = len(df_vul[df_vul['Vulnerability Label'] != 'Other']) |
|
|
|
st.markdown(f"""<div style="text-align: justify;"> The document contains a |
|
total of <span style="color: red;">{num_paragraphs}</span> paragraphs. |
|
We identified <span style="color: red;">{num_references}</span> |
|
references to vulnerable groups.</div> |
|
<br> |
|
In the pie chart on the right you can see the distribution of the different |
|
groups defined. For a more detailed view in the text, see the paragraphs and |
|
their respective labels in the table below.</div>""", unsafe_allow_html=True) |
|
|
|
with col2: |
|
|
|
|
|
|
|
df_labels = pd.DataFrame(list(label_dict.items()), columns=['Label ID', 'Label']) |
|
|
|
|
|
label_counts = df_vul['Vulnerability Label'].value_counts().reset_index() |
|
label_counts.columns = ['Label', 'Count'] |
|
|
|
|
|
df_labels = df_labels.merge(label_counts, on='Label', how='left') |
|
|
|
|
|
fig = px.pie(df_labels, |
|
names="Label", |
|
values="Count", |
|
title='Label Counts', |
|
hover_name="Count", |
|
color_discrete_sequence=px.colors.qualitative.Plotly |
|
) |
|
|
|
|
|
st.plotly_chart(fig, use_container_width=True) |
|
|
|
|
|
st.table(df_vul[df_vul['Vulnerability Label'] != 'Other']) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|