File size: 2,896 Bytes
eee7134
eab471f
 
 
5b4a98a
3f54553
a26f453
 
77a6d9d
 
 
 
 
 
a26f453
5b4a98a
 
a26f453
3f54553
27a4df7
77a6d9d
27a4df7
7f93a13
5b4a98a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27a4df7
5b4a98a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3f54553
5b4a98a
 
80a32ce
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import streamlit as st
from setfit import SetFitModel


####################################### Dashboard ######################################################

# App 
st.title("Identify references to vulnerable groups.")

st.write("""Vulnerable groups encompass various communities and individuals who are disproportionately affected by the impacts of climate change
due to their socioeconomic status, geographical location, or inherent characteristics. By incorporating the needs and perspectives of these groups 
into national climate policies, governments can ensure equitable outcomes, promote social justice, and strive to build resilience within the most marginalized populations, 
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 
references to vulnerable groups, for example when talking about policy documents.""")

# Document upload
uploaded_file = st.file_uploader(label, type=None, accept_multiple_files=False, key=None, help=None, on_change=None, args=None, kwargs=None, *, disabled=False, label_visibility="visible")

# Create text input box
#input_text = st.text_area(label='Please enter your text here', value="This policy has been implemented to support women.")

#st.write('Prediction:', model(input_text))

######################################### Model #########################################################

# Load the model
model = SetFitModel.from_pretrained("leavoigt/vulnerable_groups")

# Define the classes
id2label = {
    0: 'Agricultural communities',
    1: 'Children and Youth',
    2: 'Coastal communities',
    3: 'Drought-prone regions',
    4: 'Economically disadvantaged communities',
    5: 'Elderly population',
    6: 'Ethnic minorities and indigenous people',
    7: 'Informal sector workers',
    8: 'Migrants and Refugees',
    9: 'Other',
    10: 'People with Disabilities',
    11: 'Rural populations',
    12: 'Sexual minorities (LGBTQI+)',
    13: 'Urban populations',
    14: 'Women'}

# Import the file_processing function 
from file_processing.py import get_paragraphs

# Process document to paragraphs 
par_list = process_documents(uploaded_file)

# Make predictions 
preds = vg_model(par_list)

# Get label names 
preds_list = preds.tolist()

predictions_names=[]

# loop through each prediction
for ele in preds_list:
  try:
    index_of_one = ele.index(1)
  except ValueError:
    index_of_one = "NA" 
  if index_of_one != "NA": 
    name  = id2label[index_of_one]
  else: 
    name = "NA"
    predictions_names.append(name)

# Combine the paragraphs and labels to a dataframe 
df_predictions = pd.DataFrame({'Paragraph': par_list, 'Prediction': predictions_names})

# Drop all "Other" and "NA" predictions
filtered_df = df[df['Prediction'].isin(['Other', 'NA'])]


#####################################
st.write(df)