leavoigt commited on
Commit
f2335c5
·
1 Parent(s): 99992e5

Update appStore/groups.py

Browse files
Files changed (1) hide show
  1. appStore/groups.py +8 -132
appStore/groups.py CHANGED
@@ -22,61 +22,15 @@ import plotly.express as px
22
  classifier_identifier = 'group_classification'
23
  params = get_classifier_params(classifier_identifier)
24
 
25
- @st.cache_data
26
- def to_excel(df):
27
- df['Target Validation'] = 'No'
28
- df['Netzero Validation'] = 'No'
29
- df['GHG Validation'] = 'No'
30
- df['Adapt-Mitig Validation'] = 'No'
31
- df['Sector'] = 'No'
32
- len_df = len(df)
33
- output = BytesIO()
34
- writer = pd.ExcelWriter(output, engine='xlsxwriter')
35
- df.to_excel(writer, index=False, sheet_name='Sheet1')
36
- workbook = writer.book
37
- worksheet = writer.sheets['Sheet1']
38
- worksheet.data_validation('L2:L{}'.format(len_df),
39
- {'validate': 'list',
40
- 'source': ['No', 'Yes', 'Discard']})
41
- worksheet.data_validation('M2:L{}'.format(len_df),
42
- {'validate': 'list',
43
- 'source': ['No', 'Yes', 'Discard']})
44
- worksheet.data_validation('N2:L{}'.format(len_df),
45
- {'validate': 'list',
46
- 'source': ['No', 'Yes', 'Discard']})
47
- worksheet.data_validation('O2:L{}'.format(len_df),
48
- {'validate': 'list',
49
- 'source': ['No', 'Yes', 'Discard']})
50
- worksheet.data_validation('P2:L{}'.format(len_df),
51
- {'validate': 'list',
52
- 'source': ['No', 'Yes', 'Discard']})
53
- writer.save()
54
- processed_data = output.getvalue()
55
- return processed_data
56
-
57
  def app():
58
 
59
  ### Main app code ###
60
  with st.container():
61
-
62
- if 'key1' in st.session_state:
63
- df = st.session_state.key1
64
- classifier = load_policyactionClassifier(classifier_name=params['model_name'])
65
- st.session_state['{}_classifier'.format(classifier_identifier)] = classifier
66
-
67
- if sum(df['Target Label'] == 'TARGET') > 100:
68
- warning_msg = ": This might take sometime, please sit back and relax."
69
- else:
70
- warning_msg = ""
71
-
72
- df = policyaction_classification(haystack_doc=df,
73
- threshold= params['threshold'])
74
-
75
- st.session_state.key1 = df
76
 
77
-
78
-
79
- def action_display():
 
80
  if 'key1' in st.session_state:
81
  df = st.session_state.key1
82
 
@@ -87,46 +41,7 @@ def action_display():
87
  range_val = min(5,len(hits))
88
  if range_val !=0:
89
  count_action = len(hits)
90
- #count_netzero = sum(hits['Netzero Label'] == 'NETZERO')
91
- #count_ghg = sum(hits['GHG Label'] == 'GHG')
92
- #count_economy = sum([True if 'Economy-wide' in x else False
93
- # for x in hits['Sector Label']])
94
-
95
- # count_df = df['Target Label'].value_counts()
96
- # count_df = count_df.rename('count')
97
- # count_df = count_df.rename_axis('Target Label').reset_index()
98
- # count_df['Label_def'] = count_df['Target Label'].apply(lambda x: _lab_dict[x])
99
-
100
- # fig = px.bar(count_df, y="Label_def", x="count", orientation='h', height=200)
101
- # c1, c2 = st.columns([1,1])
102
- # with c1:
103
- # st.write('**Target Paragraphs**: `{}`'.format(count_target))
104
- # st.write('**NetZero Related Paragraphs**: `{}`'.format(count_netzero))
105
- #
106
- # # st.plotly_chart(fig,use_container_width= True)
107
- #
108
- # count_netzero = sum(hits['Netzero Label'] == 'NETZERO')
109
- # count_ghg = sum(hits['GHG Label'] == 'LABEL_2')
110
- # count_economy = sum([True if 'Economy-wide' in x else False
111
- # for x in hits['Sector Label']])
112
- # with c2:
113
- # st.write('**GHG Related Paragraphs**: `{}`'.format(count_ghg))
114
- # st.write('**Economy-wide Related Paragraphs**: `{}`'.format(count_economy))
115
- # st.write('-------------------')
116
- # hits = hits.sort_values(by=['Relevancy'], ascending=False)
117
- # netzerohit = hits[hits['Netzero Label'] == 'NETZERO']
118
- # if not netzerohit.empty:
119
- # netzerohit = netzerohit.sort_values(by = ['Netzero Score'], ascending = False)
120
- # # st.write('-------------------')
121
- # st.markdown("###### Netzero paragraph ######")
122
- # st.write('**Netzero paragraph** `page {}`: {}'.format(netzerohit.iloc[0]['page'],
123
- # netzerohit.iloc[0]['text'].replace("\n", " ")))
124
- # st.write("")
125
- # else:
126
- # st.info("🤔 No Netzero paragraph found")
127
 
128
- # st.write("**Result {}** `page {}` (Relevancy Score: {:.2f})'".format(i+1,hits.iloc[i]['page'],hits.iloc[i]['Relevancy'])")
129
- # st.write('-------------------')
130
  st.write("")
131
  st.markdown("###### Top few Action Classified paragraph/text results from list of {} classified paragraphs ######".format(count_action))
132
  st.markdown("""<hr style="height:10px;border:none;color:#097969;background-color:#097969;" /> """, unsafe_allow_html=True)
@@ -157,7 +72,7 @@ def action_display():
157
  st.info("🤔 No Actions found")
158
 
159
 
160
- def policy_display():
161
  if 'key1' in st.session_state:
162
  df = st.session_state.key1
163
 
@@ -168,46 +83,7 @@ def policy_display():
168
  range_val = min(5,len(hits))
169
  if range_val !=0:
170
  count_policy = len(hits)
171
- #count_netzero = sum(hits['Netzero Label'] == 'NETZERO')
172
- #count_ghg = sum(hits['GHG Label'] == 'GHG')
173
- #count_economy = sum([True if 'Economy-wide' in x else False
174
- # for x in hits['Sector Label']])
175
-
176
- # count_df = df['Target Label'].value_counts()
177
- # count_df = count_df.rename('count')
178
- # count_df = count_df.rename_axis('Target Label').reset_index()
179
- # count_df['Label_def'] = count_df['Target Label'].apply(lambda x: _lab_dict[x])
180
-
181
- # fig = px.bar(count_df, y="Label_def", x="count", orientation='h', height=200)
182
- # c1, c2 = st.columns([1,1])
183
- # with c1:
184
- # st.write('**Target Paragraphs**: `{}`'.format(count_target))
185
- # st.write('**NetZero Related Paragraphs**: `{}`'.format(count_netzero))
186
- #
187
- # # st.plotly_chart(fig,use_container_width= True)
188
- #
189
- # count_netzero = sum(hits['Netzero Label'] == 'NETZERO')
190
- # count_ghg = sum(hits['GHG Label'] == 'LABEL_2')
191
- # count_economy = sum([True if 'Economy-wide' in x else False
192
- # for x in hits['Sector Label']])
193
- # with c2:
194
- # st.write('**GHG Related Paragraphs**: `{}`'.format(count_ghg))
195
- # st.write('**Economy-wide Related Paragraphs**: `{}`'.format(count_economy))
196
- # st.write('-------------------')
197
- # hits = hits.sort_values(by=['Relevancy'], ascending=False)
198
- # netzerohit = hits[hits['Netzero Label'] == 'NETZERO']
199
- # if not netzerohit.empty:
200
- # netzerohit = netzerohit.sort_values(by = ['Netzero Score'], ascending = False)
201
- # # st.write('-------------------')
202
- # st.markdown("###### Netzero paragraph ######")
203
- # st.write('**Netzero paragraph** `page {}`: {}'.format(netzerohit.iloc[0]['page'],
204
- # netzerohit.iloc[0]['text'].replace("\n", " ")))
205
- # st.write("")
206
- # else:
207
- # st.info("🤔 No Netzero paragraph found")
208
-
209
- # st.write("**Result {}** `page {}` (Relevancy Score: {:.2f})'".format(i+1,hits.iloc[i]['page'],hits.iloc[i]['Relevancy'])")
210
- # st.write('-------------------')
211
  st.write("")
212
  st.markdown("###### Top few Policy/Plans Classified paragraph/text results from list of {} classified paragraphs ######".format(count_policy))
213
  st.markdown("""<hr style="height:10px;border:none;color:#097969;background-color:#097969;" /> """, unsafe_allow_html=True)
@@ -232,7 +108,7 @@ def policy_display():
232
  st.write('-------------')
233
  st.download_button(label='📥 Download Result',
234
  data=df_xlsx ,
235
- file_name= 'cpu_analysis.xlsx')
236
 
237
  else:
238
- st.info("🤔 No Policy/Plans found")
 
22
  classifier_identifier = 'group_classification'
23
  params = get_classifier_params(classifier_identifier)
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  def app():
26
 
27
  ### Main app code ###
28
  with st.container():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
+ # Classify groups
31
+ df = group_classification(haystack_doc=df, threshold= params['threshold'])
32
+
33
+ def groups_display():
34
  if 'key1' in st.session_state:
35
  df = st.session_state.key1
36
 
 
41
  range_val = min(5,len(hits))
42
  if range_val !=0:
43
  count_action = len(hits)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
 
 
45
  st.write("")
46
  st.markdown("###### Top few Action Classified paragraph/text results from list of {} classified paragraphs ######".format(count_action))
47
  st.markdown("""<hr style="height:10px;border:none;color:#097969;background-color:#097969;" /> """, unsafe_allow_html=True)
 
72
  st.info("🤔 No Actions found")
73
 
74
 
75
+ def groups_display():
76
  if 'key1' in st.session_state:
77
  df = st.session_state.key1
78
 
 
83
  range_val = min(5,len(hits))
84
  if range_val !=0:
85
  count_policy = len(hits)
86
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  st.write("")
88
  st.markdown("###### Top few Policy/Plans Classified paragraph/text results from list of {} classified paragraphs ######".format(count_policy))
89
  st.markdown("""<hr style="height:10px;border:none;color:#097969;background-color:#097969;" /> """, unsafe_allow_html=True)
 
108
  st.write('-------------')
109
  st.download_button(label='📥 Download Result',
110
  data=df_xlsx ,
111
+ file_name= 'vulnerable_groups.xlsx')
112
 
113
  else:
114
+ st.info("🤔 No Groups found")