File size: 1,968 Bytes
452b339
 
 
 
 
 
034b7a6
452b339
 
 
 
 
 
 
 
 
 
 
 
 
9e957cc
452b339
 
 
 
 
 
 
 
 
 
 
 
6572390
452b339
 
 
 
 
 
 
 
 
687bee8
9e957cc
687bee8
 
 
452b339
 
 
 
 
 
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
import streamlit as st
import pandas as pd

# Load the CSV data
@st.cache_data
def load_data(file_path):
    df = pd.read_csv(file_path, delimiter=',', quotechar='"', on_bad_lines='skip')
    return df

# Paginate function
def paginate_data(df, page_number, page_size):
    start_index = page_number * page_size
    end_index = start_index + page_size
    return df[start_index:end_index]

# Streamlit app
def main():
    st.title("Emotion Filter and Pagination App")

    # Load the data
    file_path = 'enron_kaggle_clean.csv'  # Ensure this is the correct path to your uploaded CSV file
    df = load_data(file_path)

    # Dropdown for selecting emotion
    unique_emotions =  ["admiration", "amusement", "anger", "annoyance", "approval",
                  "caring", "confusion", "curiosity", "desire", "disappointment",
                  "disapproval", "disgust", "embarrassment", "excitement", "fear",
                  "gratitude", "grief", "joy", "love", "nervousness", "optimism",
                  "pride", "realization", "relief", "remorse", "sadness", "surprise",
                  "neutral"]
    selected_emotion = st.selectbox('Select Emotion', unique_emotions)

    # Filter the data based on the selected emotion and sort by score
    filtered_data = df[df['emotion'] == selected_emotion].sort_values(by='emoscore', ascending=False).head(100)

    # Pagination settings
    page_size = 10
    total_pages = (len(filtered_data) // page_size) + 1
    page_number = st.number_input('Page number', 0, total_pages - 1, 0)

    # Paginate data
    paginated_data = paginate_data(filtered_data, page_number, page_size)

    # Display total counts of each emotion
    emotion_counts = df['emotion'].value_counts()
    st.write("### Total Emails of Each Emotion")
    st.write(emotion_counts)

    # Display the paginated data
    st.write(f"Showing page {page_number + 1} of {total_pages}")
    st.write(paginated_data)

if __name__ == "__main__":
    main()