import pickle import streamlit as st reports = {"Hillary Clinton": {"emotions_report_filename" : "emotions_report.pkl", "goals_report_filename" : "goals_report.pkl"}, "Harry Potter": {"emotions_report_filename" : "hp_emotions.pkl", "goals_report_filename" : "hp_goals.pkl"} } if 'character' not in st.session_state: st.session_state.character = "Harry Potter" for ch in reports.keys(): with open(reports[ch]["goals_report_filename"], 'rb') as file: reports[ch]["goals_report"] = pickle.load(file) with open(reports[ch]["emotions_report_filename"], 'rb') as file: reports[ch]["emotions_report"] = pickle.load(file) emotions_report = reports[st.session_state.character]["emotions_report"] goals_report = reports[st.session_state.character]["goals_report"] st.title(f"{st.session_state.character}'s Contact List Analysis") emotions_tab, goals_tab = st.tabs(["Emotions", "Goals"]) with emotions_tab: for name in emotions_report.keys(): container = st.container(border=True) with container: st.header(name) for emotion in emotions_report[name].keys(): score = len(emotions_report[name][emotion]) expander = st.expander(f"Emotion: {emotion} - {score}") with expander: for r in emotions_report[name][emotion]: st.write(r["explanation"]) for ref in r["reference"]: st.markdown(f"> {ref}") st.write("\n") with goals_tab: for name in goals_report.keys(): container = st.container(border=True) with container: st.header(name) for goal in goals_report[name].keys(): score = len(goals_report[name][goal]) expander = st.expander(f"Goal: {goal} - {score}") with expander: for r in goals_report[name][goal]: st.write(r["explanation"]) for ref in r["reference"]: st.markdown(f"> {ref}") st.write("\n") with st.sidebar: for ch in reports.keys(): container = st.container(border=True) col1, col2 = container.columns([2, 1]) with col1: st.header(ch) with col2: st.button("Show", key=ch, on_click=lambda ch=ch: st.session_state.update(character=ch))