File size: 5,192 Bytes
4382380
 
 
 
 
 
 
 
 
 
 
 
 
2163302
4382380
 
 
 
 
 
 
 
2163302
4382380
 
 
2163302
4382380
2163302
 
 
 
 
4382380
2163302
4382380
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# set path
import glob, os, sys; 
sys.path.append('../utils')
from setfit import SetFitModel
#import needed libraries
#import seaborn as sns
#import matplotlib.pyplot as plt
#import numpy as np
#import pandas as pd
#import streamlit as st
from utils.groups_classifier import load_groupsClassifier, groups_classification
#import logging
#logger = logging.getLogger(__name__)
from utils.config import get_classifier_params
#from utils.preprocessing import paraLengthCheck
#from io import BytesIO
#import xlsxwriter
#import plotly.express as px

vg_model = SetFitModel.from_pretrained("leavoigt/vulnerable_groups")


# Retrieve the necessary paramaters
classifier_identifier = 'group_classification'
params  = get_classifier_params(classifier_identifier)

def app(): 

     ### Main app code ###
     with st.container():
         
         # Classify groups
         df = group_classification(haystack_doc=df, threshold= params['threshold'])
        
 def groups_display():
#     if  'key1' in st.session_state:
#         df = st.session_state.key1
                
        
#         df['Action_check']  = df['Policy-Action Label'].apply(lambda x: True if 'Action' in x else False)
#         hits  = df[df['Action_check'] == True]
#         # hits['GHG Label'] = hits['GHG Label'].apply(lambda i: _lab_dict[i])
#         range_val = min(5,len(hits))
#         if range_val !=0:
#             count_action = len(hits)

#             st.write("")
#             st.markdown("###### Top few Action Classified paragraph/text results from list of {} classified paragraphs ######".format(count_action))
#             st.markdown("""<hr style="height:10px;border:none;color:#097969;background-color:#097969;" /> """, unsafe_allow_html=True)
#             range_val = min(5,len(hits))
#             for i in range(range_val):
#                 # the page number reflects the page that contains the main paragraph 
#                 # according to split limit, the overlapping part can be on a separate page
#                 st.write('**Result {}** : `page {}`, `Sector: {}`,\
#                             `Indicators: {}`, `Adapt-Mitig :{}`'\
#                     .format(i+1,
#                             hits.iloc[i]['page'], hits.iloc[i]['Sector Label'],
#                             hits.iloc[i]['Indicator Label'],hits.iloc[i]['Adapt-Mitig Label']))                        
#                 st.write("\t Text: \t{}".format(hits.iloc[i]['text'].replace("\n", " ")))
#             hits = hits.reset_index(drop =True)
#             st.write('----------------')
#             st.write('Explore the data')
#             st.write(hits)
#             df.drop(columns = ['Action_check'],inplace=True)
#             df_xlsx = to_excel(df)
            
#             with st.sidebar:
#                 st.write('-------------')
#                 st.download_button(label='📥 Download Result',
#                             data=df_xlsx ,
#                             file_name= 'cpu_analysis.xlsx')

#         else:
#             st.info("🤔 No Actions found")


# def groups_display():
#     if  'key1' in st.session_state:
#         df = st.session_state.key1
                
        
#         df['Policy_check']  = df['Policy-Action Label'].apply(lambda x: True if 'Policies & Plans' in x else False)
#         hits  = df[df['Policy_check'] == True]
#         # hits['GHG Label'] = hits['GHG Label'].apply(lambda i: _lab_dict[i])
#         range_val = min(5,len(hits))
#         if range_val !=0:
#             count_policy = len(hits)
    
#             st.write("")
#             st.markdown("###### Top few Policy/Plans Classified paragraph/text results from list of {} classified paragraphs ######".format(count_policy))
#             st.markdown("""<hr style="height:10px;border:none;color:#097969;background-color:#097969;" /> """, unsafe_allow_html=True)
#             range_val = min(5,len(hits))
#             for i in range(range_val):
#                 # the page number reflects the page that contains the main paragraph 
#                 # according to split limit, the overlapping part can be on a separate page
#                 st.write('**Result {}** : `page {}`, `Sector: {}`,\
#                             `Indicators: {}`, `Adapt-Mitig :{}`'\
#                     .format(i+1,
#                             hits.iloc[i]['page'], hits.iloc[i]['Sector Label'],
#                             hits.iloc[i]['Indicator Label'],hits.iloc[i]['Adapt-Mitig Label']))                        
#                 st.write("\t Text: \t{}".format(hits.iloc[i]['text'].replace("\n", " ")))
#             hits = hits.reset_index(drop =True)
#             st.write('----------------')
#             st.write('Explore the data')
#             st.write(hits)
#             df.drop(columns = ['Policy_check'],inplace=True)
#             df_xlsx = to_excel(df)
            
#             with st.sidebar:
#                 st.write('-------------')
#                 st.download_button(label='📥 Download Result',
#                             data=df_xlsx ,
#                             file_name= 'vulnerable_groups.xlsx')

#         else:
#             st.info("🤔 No Groups found")