EmotionCSV / app.py
umang018's picture
Create app.py
452b339 verified
raw
history blame
1.74 kB
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)
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 = 'your_data.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_label'] == 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 the paginated data
st.write(f"Showing page {page_number + 1} of {total_pages}")
st.write(paginated_data)
if __name__ == "__main__":
main()