leavoigt commited on
Commit
5b4a98a
1 Parent(s): de24a6f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -51
app.py CHANGED
@@ -1,46 +1,8 @@
1
  import streamlit as st
2
  from setfit import SetFitModel
3
 
4
- # Load the model
5
- model = SetFitModel.from_pretrained("leavoigt/vulnerable_groups")
6
 
7
- # Define the classes
8
- group_dict = {
9
- 0: 'Coastal communities',
10
- 1: 'Small island developing states (SIDS)',
11
- 2: 'Landlocked countries',
12
- 3: 'Low-income households',
13
- 4: 'Informal settlements and slums',
14
- 5: 'Rural communities',
15
- 6: 'Children and youth',
16
- 7: 'Older adults and the elderly',
17
- 8: 'Women and girls',
18
- 9: 'People with pre-existing health conditions',
19
- 10: 'People with disabilities',
20
- 11: 'Small-scale farmers and subsistence agriculture',
21
- 12: 'Fisherfolk and fishing communities',
22
- 13: 'Informal sector workers',
23
- 14: 'Children with disabilities',
24
- 15: 'Remote communities',
25
- 16: 'Young adults',
26
- 17: 'Elderly population',
27
- 18: 'Urban slums',
28
- 19: 'Men and boys',
29
- 20: 'Gender non-conforming individuals',
30
- 21: 'Pregnant women and new mothers',
31
- 22: 'Mountain communities',
32
- 23: 'Riverine and flood-prone areas',
33
- 24: 'Drought-prone regions',
34
- 25: 'Indigenous peoples',
35
- 26: 'Migrants and displaced populations',
36
- 27: 'Outdoor workers',
37
- 28: 'Small-scale farmers',
38
- 29: 'Other'}
39
-
40
- # Define prediction function
41
- #def predict(text):
42
- # preds = model(text)
43
- # return group_dict[preds]
44
 
45
  # App
46
  st.title("Identify references to vulnerable groups.")
@@ -51,23 +13,70 @@ into national climate policies, governments can ensure equitable outcomes, promo
51
  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
52
  references to vulnerable groups, for example when talking about policy documents.""")
53
 
 
 
54
 
55
  # Create text input box
56
  input_text = st.text_area(label='Please enter your text here', value="This policy has been implemented to support women.")
57
 
58
  st.write('Prediction:', model(input_text))
59
 
60
- # Make predictions
61
- #preds = model(input_text)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
- #modelresponse = model_function(input)
64
- #st.text_area(label ="",value=preds, height =100)
65
 
66
- # Select lab
67
- #def get_label(prediction_tensor):
68
- # print(prediction_tensor.index("1"))
69
- #key = prediction_tensor.index(1)
70
- #return group_dict[key]
71
-
72
- #st.write(preds)
73
- #st.text(get_label(preds))
 
1
  import streamlit as st
2
  from setfit import SetFitModel
3
 
 
 
4
 
5
+ ####################################### Dashboard ######################################################
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  # App
8
  st.title("Identify references to vulnerable groups.")
 
13
  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
14
  references to vulnerable groups, for example when talking about policy documents.""")
15
 
16
+ # Document upload
17
+ 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")
18
 
19
  # Create text input box
20
  input_text = st.text_area(label='Please enter your text here', value="This policy has been implemented to support women.")
21
 
22
  st.write('Prediction:', model(input_text))
23
 
24
+ ######################################### Model #########################################################
25
+
26
+ # Load the model
27
+ model = SetFitModel.from_pretrained("leavoigt/vulnerable_groups")
28
+
29
+ # Define the classes
30
+ id2label = {
31
+ 0: 'Agricultural communities',
32
+ 1: 'Children and Youth',
33
+ 2: 'Coastal communities',
34
+ 3: 'Drought-prone regions',
35
+ 4: 'Economically disadvantaged communities',
36
+ 5: 'Elderly population',
37
+ 6: 'Ethnic minorities and indigenous people',
38
+ 7: 'Informal sector workers',
39
+ 8: 'Migrants and Refugees',
40
+ 9: 'Other',
41
+ 10: 'People with Disabilities',
42
+ 11: 'Rural populations',
43
+ 12: 'Sexual minorities (LGBTQI+)',
44
+ 13: 'Urban populations',
45
+ 14: 'Women'}
46
+
47
+ # Import the file_processing function
48
+ from file_processing.py import process_documents
49
+
50
+ # Process document to paragraphs
51
+ par_list = process_documents(uploaded_file)
52
+
53
+ # Make predictions
54
+ preds = vg_model(par_list)
55
+
56
+ # Get label names
57
+ preds_list = preds.tolist()
58
+
59
+ predictions_names=[]
60
+
61
+ # loop through each prediction
62
+ for ele in preds_list:
63
+ try:
64
+ index_of_one = ele.index(1)
65
+ except ValueError:
66
+ index_of_one = "NA"
67
+ if index_of_one != "NA":
68
+ name = id2label[index_of_one]
69
+ else:
70
+ name = "NA"
71
+ predictions_names.append(name)
72
+
73
+ # Combine the paragraphs and labels to a dataframe
74
+ df_predictions = pd.DataFrame({'Paragraph': par_list, 'Prediction': predictions_names})
75
+
76
+ # Drop all "Other" and "NA" predictions
77
+ filtered_df = df[df['Prediction'].isin(['Other', 'NA'])]
78
+
79
 
80
+ #####################################
81
+ st.write(df)
82