File size: 2,591 Bytes
b48aa5f
36313b3
b48aa5f
36313b3
 
 
 
 
b48aa5f
36313b3
 
b48aa5f
36313b3
 
 
 
 
 
b48aa5f
36313b3
 
 
 
b48aa5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36313b3
 
 
 
 
 
 
 
 
 
 
 
 
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
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))