Spaces:
Sleeping
Sleeping
Updating
Browse files- app.py +67 -70
- doc_processing.py +0 -2
app.py
CHANGED
|
@@ -1,21 +1,61 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from
|
| 3 |
-
from file_processing import get_paragraphs
|
| 4 |
-
import doc_processing as processing
|
| 5 |
|
| 6 |
####################################### Dashboard ######################################################
|
| 7 |
|
| 8 |
# App
|
| 9 |
-
st.title("Identify references to vulnerable groups.")
|
| 10 |
|
| 11 |
-
st.
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
# Document upload
|
| 18 |
-
uploaded_file = st.file_uploader("Upload your file here")
|
| 19 |
|
| 20 |
# Create text input box
|
| 21 |
#input_text = st.text_area(label='Please enter your text here', value="This policy has been implemented to support women.")
|
|
@@ -25,25 +65,25 @@ uploaded_file = st.file_uploader("Upload your file here")
|
|
| 25 |
######################################### Model #########################################################
|
| 26 |
|
| 27 |
# Load the model
|
| 28 |
-
model = SetFitModel.from_pretrained("leavoigt/vulnerable_groups")
|
| 29 |
|
| 30 |
# Define the classes
|
| 31 |
-
id2label = {
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
|
| 48 |
|
| 49 |
### Process document to paragraphs
|
|
@@ -62,46 +102,3 @@ id2label = {
|
|
| 62 |
|
| 63 |
# #Get the file path
|
| 64 |
|
| 65 |
-
file = st.file_uploader("File upload", type=['pdf', 'docx', 'txt'])
|
| 66 |
-
|
| 67 |
-
if uploaded_file is not None:
|
| 68 |
-
|
| 69 |
-
# Retrieve the file name
|
| 70 |
-
with tempfile.NamedTemporaryFile(mode="wb") as temp:
|
| 71 |
-
bytes_data = files.getvalue()
|
| 72 |
-
temp.write(bytes_data)
|
| 73 |
-
print(temp.name)
|
| 74 |
-
|
| 75 |
-
# Process file
|
| 76 |
-
par_list = get_paragraphs(temp.name)
|
| 77 |
-
|
| 78 |
-
### Make predictions
|
| 79 |
-
preds = vg_model(par_list)
|
| 80 |
-
|
| 81 |
-
# Get label names
|
| 82 |
-
preds_list = preds.tolist()
|
| 83 |
-
|
| 84 |
-
predictions_names=[]
|
| 85 |
-
|
| 86 |
-
# loop through each prediction
|
| 87 |
-
for ele in preds_list:
|
| 88 |
-
try:
|
| 89 |
-
index_of_one = ele.index(1)
|
| 90 |
-
except ValueError:
|
| 91 |
-
index_of_one = "NA"
|
| 92 |
-
if index_of_one != "NA":
|
| 93 |
-
name = id2label[index_of_one]
|
| 94 |
-
else:
|
| 95 |
-
name = "NA"
|
| 96 |
-
predictions_names.append(name)
|
| 97 |
-
|
| 98 |
-
# Combine the paragraphs and labels to a dataframe
|
| 99 |
-
df_predictions = pd.DataFrame({'Paragraph': par_list, 'Prediction': predictions_names})
|
| 100 |
-
|
| 101 |
-
# Drop all "Other" and "NA" predictions
|
| 102 |
-
filtered_df = df[df['Prediction'].isin(['Other', 'NA'])]
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
#####################################
|
| 106 |
-
st.write(df)
|
| 107 |
-
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from utils.uploadAndExample import add_upload
|
|
|
|
|
|
|
| 3 |
|
| 4 |
####################################### Dashboard ######################################################
|
| 5 |
|
| 6 |
# App
|
|
|
|
| 7 |
|
| 8 |
+
st.set_page_config(page_title = 'Vulnerable Groups Identification',
|
| 9 |
+
initial_sidebar_state='expanded', layout="wide")
|
| 10 |
+
|
| 11 |
+
with st.sidebar:
|
| 12 |
+
# upload and example doc
|
| 13 |
+
choice = st.sidebar.radio(label = 'Select the Document',
|
| 14 |
+
help = 'You can upload the document \
|
| 15 |
+
or else you can try a example document',
|
| 16 |
+
options = ('Upload Document', 'Try Example'),
|
| 17 |
+
horizontal = True)
|
| 18 |
+
add_upload(choice)
|
| 19 |
+
|
| 20 |
+
with st.container():
|
| 21 |
+
st.markdown("<h2 style='text-align: center; color: black;'> Vulnerable Groups Identification </h2>", unsafe_allow_html=True)
|
| 22 |
+
st.write(' ')
|
| 23 |
+
|
| 24 |
+
with st.expander("ℹ️ - About this app", expanded=False):
|
| 25 |
+
st.write(
|
| 26 |
+
"""
|
| 27 |
+
The Vulnerable Groups Identification App is an open-source\
|
| 28 |
+
digital tool which aims to assist policy analysts and \
|
| 29 |
+
other users in extracting and filtering relevant \
|
| 30 |
+
information from public documents.
|
| 31 |
+
""")
|
| 32 |
+
st.write('**Definitions**')
|
| 33 |
+
|
| 34 |
+
st.caption("""
|
| 35 |
+
- **Place holder**: Place holder \
|
| 36 |
+
Place holder \
|
| 37 |
+
Place holder \
|
| 38 |
+
Place holder \
|
| 39 |
+
Place holder
|
| 40 |
+
""")
|
| 41 |
+
#c1, c2, c3 = st.columns([12,1,10])
|
| 42 |
+
#with c1:
|
| 43 |
+
#image = Image.open('docStore/img/flow.jpg')
|
| 44 |
+
#st.image(image)
|
| 45 |
+
#with c3:
|
| 46 |
+
#st.write("""
|
| 47 |
+
#What Happens in background?
|
| 48 |
+
|
| 49 |
+
#st.title("Identify references to vulnerable groups.")
|
| 50 |
+
|
| 51 |
+
#st.write("""Vulnerable groups encompass various communities and individuals who are disproportionately affected by the impacts of climate change
|
| 52 |
+
#due to their socioeconomic status, geographical location, or inherent characteristics. By incorporating the needs and perspectives of these groups
|
| 53 |
+
#into national climate policies, governments can ensure equitable outcomes, promote social justice, and strive to build resilience within the most marginalized populations,
|
| 54 |
+
#fostering a more sustainable and inclusive society as we navigate the challenges posed by climate change.This app allows you to identify whether a text contains any
|
| 55 |
+
#references to vulnerable groups, for example when talking about policy documents.""")
|
| 56 |
|
| 57 |
# Document upload
|
| 58 |
+
#uploaded_file = st.file_uploader("Upload your file here")
|
| 59 |
|
| 60 |
# Create text input box
|
| 61 |
#input_text = st.text_area(label='Please enter your text here', value="This policy has been implemented to support women.")
|
|
|
|
| 65 |
######################################### Model #########################################################
|
| 66 |
|
| 67 |
# Load the model
|
| 68 |
+
#model = SetFitModel.from_pretrained("leavoigt/vulnerable_groups")
|
| 69 |
|
| 70 |
# Define the classes
|
| 71 |
+
#id2label = {
|
| 72 |
+
# 0: 'Agricultural communities',
|
| 73 |
+
# 1: 'Children and Youth',
|
| 74 |
+
# 2: 'Coastal communities',
|
| 75 |
+
# 3: 'Drought-prone regions',
|
| 76 |
+
# 4: 'Economically disadvantaged communities',
|
| 77 |
+
# 5: 'Elderly population',
|
| 78 |
+
# 6: 'Ethnic minorities and indigenous people',
|
| 79 |
+
# 7: 'Informal sector workers',
|
| 80 |
+
# 8: 'Migrants and Refugees',
|
| 81 |
+
# 9: 'Other',
|
| 82 |
+
# 10: 'People with Disabilities',
|
| 83 |
+
# 11: 'Rural populations',
|
| 84 |
+
# 12: 'Sexual minorities (LGBTQI+)',
|
| 85 |
+
# 13: 'Urban populations',
|
| 86 |
+
# 14: 'Women'}
|
| 87 |
|
| 88 |
|
| 89 |
### Process document to paragraphs
|
|
|
|
| 102 |
|
| 103 |
# #Get the file path
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
doc_processing.py
CHANGED
|
@@ -54,8 +54,6 @@ def runPreprocessingPipeline(file_name:str, file_path:str,
|
|
| 54 |
|
| 55 |
return output_pre
|
| 56 |
|
| 57 |
-
st.write("Hello World")
|
| 58 |
-
|
| 59 |
def app():
|
| 60 |
with st.container():
|
| 61 |
if 'filepath' in st.session_state:
|
|
|
|
| 54 |
|
| 55 |
return output_pre
|
| 56 |
|
|
|
|
|
|
|
| 57 |
def app():
|
| 58 |
with st.container():
|
| 59 |
if 'filepath' in st.session_state:
|