CPo_droid / appStore /tapp_display.py
ppsingh's picture
Create tapp_display.py
91f38ae verified
raw
history blame
2.56 kB
# 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
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['MitigationLabel'] == 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))
with c2:
st.write('**GHG Target Related Paragraphs**: `{}`'.format(count_ghg))
st.write('**NonGHG Target Related Paragraphs**: `{}`'.format(count_nonghg))
st.write('----------------')
if count_netzero !=0:
st.write("NetZero Target:",st.session_state['netzero'])
else:
st.info("🤔 No Netzero paragraph found")
#st.dataframe(hits[['keep','text','Parameter','page']])
else:
st.info("🤔 No Targets Found")