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='score', 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()