Create tapp_display.py
Browse files- appStore/tapp_display.py +70 -0
appStore/tapp_display.py
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# set path
|
2 |
+
import glob, os, sys;
|
3 |
+
sys.path.append('../utils')
|
4 |
+
|
5 |
+
#import needed libraries
|
6 |
+
import seaborn as sns
|
7 |
+
import matplotlib.pyplot as plt
|
8 |
+
import numpy as np
|
9 |
+
import pandas as pd
|
10 |
+
import streamlit as st
|
11 |
+
from st_aggrid import AgGrid
|
12 |
+
import logging
|
13 |
+
logger = logging.getLogger(__name__)
|
14 |
+
from io import BytesIO
|
15 |
+
import xlsxwriter
|
16 |
+
import plotly.express as px
|
17 |
+
from pandas.api.types import (
|
18 |
+
is_categorical_dtype,
|
19 |
+
is_datetime64_any_dtype,
|
20 |
+
is_numeric_dtype,
|
21 |
+
is_object_dtype,
|
22 |
+
is_list_like)
|
23 |
+
|
24 |
+
|
25 |
+
|
26 |
+
|
27 |
+
def targets():
|
28 |
+
if 'key1' in st.session_state:
|
29 |
+
df = st.session_state['key1'].copy()
|
30 |
+
idx = df['NetzeroLabel_Score'].idxmax()
|
31 |
+
netzero_placeholder = df.loc[idx, 'text']
|
32 |
+
df = df.drop(df.filter(regex='Score').columns, axis=1)
|
33 |
+
df = df[df.TargetLabel==True].reset_index(drop=True)
|
34 |
+
df['keep'] = True
|
35 |
+
st.session_state['target_hits'] = df
|
36 |
+
st.session_state['netzero'] = netzero_placeholder
|
37 |
+
|
38 |
+
def target_display():
|
39 |
+
if 'key1' in st.session_state:
|
40 |
+
st.caption(""" **{}** is splitted into **{}** paragraphs/text chunks."""\
|
41 |
+
.format(os.path.basename(st.session_state['filename']),
|
42 |
+
len(st.session_state['key0'])))
|
43 |
+
|
44 |
+
hits = st.session_state['target_hits']
|
45 |
+
if len(hits) !=0:
|
46 |
+
# collecting some statistics
|
47 |
+
count_target = sum(hits['TargetLabel'] == True)
|
48 |
+
count_ghg = sum(hits['GHGLabel'] == True)
|
49 |
+
count_netzero = sum(hits['NetzeroLabel'] == True)
|
50 |
+
count_nonghg = sum(hits['NonGHGLabel'] == True)
|
51 |
+
count_Mitigation = sum(hits['MitigationLabel'] == True)
|
52 |
+
count_Adaptation = sum(hits['MitigationLabel'] == True)
|
53 |
+
|
54 |
+
|
55 |
+
c1, c2 = st.columns([1,1])
|
56 |
+
with c1:
|
57 |
+
st.write('**Target Related Paragraphs**: `{}`'.format(count_target))
|
58 |
+
st.write('**Netzero Related Paragraphs**: `{}`'.format(count_netzero))
|
59 |
+
with c2:
|
60 |
+
st.write('**GHG Target Related Paragraphs**: `{}`'.format(count_ghg))
|
61 |
+
st.write('**NonGHG Target Related Paragraphs**: `{}`'.format(count_nonghg))
|
62 |
+
st.write('----------------')
|
63 |
+
|
64 |
+
if count_netzero !=0:
|
65 |
+
st.write("NetZero Target:",st.session_state['netzero'])
|
66 |
+
else:
|
67 |
+
st.info("🤔 No Netzero paragraph found")
|
68 |
+
#st.dataframe(hits[['keep','text','Parameter','page']])
|
69 |
+
else:
|
70 |
+
st.info("🤔 No Targets Found")
|