File size: 2,693 Bytes
0ee871b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 pandas as pd
import streamlit as st
import plotly.express as px
import streamlit.components.v1 as components


def character_evolution(character_list):
    index = ['Philosopher\'s Stone',
             'Chamber of Secrets',
             'Prisoner of Azkaban',
             'Goblet of Fire',
             'Order of the Phoenix',
             'Half-Blood Prince',
             'Deathly Hallows']
    
    df = pd.read_csv('character_evolution.csv')
    df = df.set_index(pd.Index(index))
    
    fig = px.line(df[character_list], markers=True) 
    fig.update_layout(height=550,
                      width=1000, 
                      xaxis_title="",
                      yaxis_title="Importance",
                      title={'text': "Evolution of Characters over the Books",
                             'y': 0.95,
                             'x': 0.5,
                             'xanchor': 'center',
                             'yanchor': 'top'})
    left, middle, right = st.columns((2, 5, 2))
    with middle:
        st.plotly_chart(fig, theme=None, use_container_width=False)


def main():
    df = pd.read_csv('character_evolution.csv')
    
    st.set_page_config(layout="wide")
    st.title("Relationship Extraction in Harry Potter Books")
    st.write('')
    st.write('')
    
    # Select Type of Analysis
    tab1, tab2 = st.tabs(['Network Graphs',
                          'Evolution of Characters'
                        ])
    
    # Network Graphs
    with tab1:
        st.write('')
        book = st.selectbox('Pick a Book to generate its graph', 
                            ['1. Philosopher\'s Stone',
                             '2. Chamber of Secrets',
                             '3. Prisoner of Azkaban',
                             '4. Goblet of Fire',
                             '5. Order of the Phoenix',
                             '6. Half-Blood Prince',
                             '7. Deathly Hallows',
                             'All Books Combined'])
        
        if st.button('Show Graph'):
            left, middle, right = st.columns((1, 5, 1))
            with middle:
                st.write('') 
                HtmlFile = open(f'graphs/{book}.html', 'r', encoding='utf-8')
                components.html(HtmlFile.read(), height=1500, width=1000)

    # Evolution of Characters
    with tab2:
        st.write('')
        character_list = st.multiselect('Select Characters', list(df.columns)[1:])
        if st.button('Plot'):
            st.write('')
            character_evolution(character_list)
        

if __name__ == '__main__':
    main()