File size: 5,538 Bytes
91f38ae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
db65cd7
91f38ae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b805749
 
91f38ae
 
 
 
 
 
3489bcc
91f38ae
 
 
3489bcc
91f38ae
533a3db
 
 
db65cd7
fbab372
533a3db
db65cd7
 
0dde0c7
db65cd7
 
 
 
318de35
91f38ae
 
b805749
 
 
533a3db
b805749
 
 
533a3db
b805749
533a3db
 
b805749
533a3db
b805749
 
 
 
 
533a3db
b805749
 
533a3db
b805749
 
 
 
 
 
533a3db
b805749
 
 
 
533a3db
b805749
533a3db
b805749
 
 
 
 
 
 
 
 
533a3db
b805749
 
 
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# set path
import glob, os, sys; 
sys.path.append('../utils')

#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 st_aggrid import AgGrid
import logging
logger = logging.getLogger(__name__)
from io import BytesIO
import xlsxwriter
import plotly.express as px
from pandas.api.types import (
    is_categorical_dtype,
    is_datetime64_any_dtype,
    is_numeric_dtype,
    is_object_dtype,
    is_list_like)


           
            
def targets():
    if 'key1' in st.session_state:
        df = st.session_state['key1'].copy()
        idx = df['NetzeroLabel_Score'].idxmax()
        netzero_placeholder = df.loc[idx, 'text']
        df = df.drop(df.filter(regex='Score').columns, axis=1)
        df = df[df.TargetLabel==True].reset_index(drop=True)
        df['keep'] = True
        df.drop(columns = ['ActionLabel','PolicyLabel','PlansLabel'], inplace=True)
        st.session_state['target_hits'] = df
        st.session_state['netzero'] = netzero_placeholder
    
def target_display():
    if 'key1' in st.session_state:
        st.caption(""" **{}** is splitted into **{}** paragraphs/text chunks."""\
                          .format(os.path.basename(st.session_state['filename']),
                                 len(st.session_state['key0'])))   
        
        hits  = st.session_state['target_hits']
        if len(hits) !=0:
            # collecting some statistics
            count_target = sum(hits['TargetLabel'] == True)
            count_ghg = sum(hits['GHGLabel'] == True)
            count_netzero = sum(hits['NetzeroLabel'] == True)
            count_nonghg = sum(hits['NonGHGLabel'] == True)
            count_mitigation = sum(hits['MitigationLabel'] == True)
            count_adaptation = sum(hits['AdaptationLabel'] == True)
            

            c1, c2 = st.columns([1,1])
            with c1:
                st.write('**Target Related Paragraphs**: `{}`'.format(count_target))
                st.write('**Netzero Related Paragraphs**: `{}`'.format(count_netzero))
                st.write('**Mitigation Related Paragraphs**: `{}`'.format(count_mitigation))
            with c2:
                st.write('**GHG Target Related Paragraphs**: `{}`'.format(count_ghg))
                st.write('**NonGHG Target Related Paragraphs**: `{}`'.format(count_nonghg))
                st.write('**Adaptation Related Paragraphs**: `{}`'.format(count_adaptation))
            st.write('----------------')

            st.markdown("<h4 style='text-align: left; color: black;'> Sectoral Target Related Paragraphs Count </h4>", unsafe_allow_html=True)
            
            cols = list(hits.columns)
            sector_cols = list(set(cols) - {'TargetLabel','MitigationLabel','AdaptationLabel','GHGLabel','NetzeroLabel','NonGHGLabel','text','keep','page'})
            
            placeholder= []
            for col in sector_cols:
                placeholder.append({'Sector':col,'Count':sum(hits[col] == True)})
            sector_df = pd.DataFrame.from_dict(placeholder)
            fig = px.bar(sector_df, x='Sector', y='Count')
            st.plotly_chart(fig,use_container_width= True)
                
            st.dataframe(hits)
        else:
            st.info("🤔 No Targets Found")



def actions():
    if 'key1' in st.session_state:
        df = st.session_state['key1'].copy()
        df = df.drop(df.filter(regex='Score').columns, axis=1)
        df = df[df.ActionLabel==True].reset_index(drop=True)
        df['keep'] = True
        df.drop(columns = ['TargetLabel','PolicyLabel','PlansLabel','GHGLabel','NetzeroLabel','NonGHGLabel'], inplace=True)
        st.session_state['action_hits'] = df
    
def action_display():
    if 'key1' in st.session_state:
        st.caption(""" **{}** is splitted into **{}** paragraphs/text chunks."""\
                          .format(os.path.basename(st.session_state['filename']),
                                 len(st.session_state['key0'])))   
        
        hits  = st.session_state['action_hits']
        if len(hits) !=0:
            # collecting some statistics
            count_action = sum(hits['ActionLabel'] == True)
            count_mitigation = sum(hits['MitigationLabel'] == True)
            count_adaptation = sum(hits['AdaptationLabel'] == True)
            

            c1, c2 = st.columns([1,1])
            with c1:
                st.write('**Action Related Paragraphs**: `{}`'.format(count_action))
                st.write('**Mitigation Related Paragraphs**: `{}`'.format(count_mitigation))
            with c2:
                st.write('**Adaptation Related Paragraphs**: `{}`'.format(count_adaptation))
            st.write('----------------')
            st.markdown("<h4 style='text-align: left; color: black;'> Sectoral Action Related Paragraphs Count </h4>", unsafe_allow_html=True)
            cols = list(hits.columns)
            sector_cols = list(set(cols) - {'ActionLabel','MitigationLabel','AdaptationLabel','GHGLabel','NetzeroLabel','NonGHGLabel','text','keep','page'})
            placeholder= []
            for col in sector_cols:
                placeholder.append({'Sector':col,'Count':sum(hits[col] == True)})
            sector_df = pd.DataFrame.from_dict(placeholder)
            fig = px.bar(sector_df, x='Sector', y='Count')
            st.plotly_chart(fig,use_container_width= True)
                
            st.dataframe(hits)
        else:
            st.info("🤔 No Actions Found")