Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
|
4 |
+
# Load the CSV data
|
5 |
+
@st.cache_data
|
6 |
+
def load_data(file_path):
|
7 |
+
df = pd.read_csv(file_path)
|
8 |
+
return df
|
9 |
+
|
10 |
+
# Paginate function
|
11 |
+
def paginate_data(df, page_number, page_size):
|
12 |
+
start_index = page_number * page_size
|
13 |
+
end_index = start_index + page_size
|
14 |
+
return df[start_index:end_index]
|
15 |
+
|
16 |
+
# Streamlit app
|
17 |
+
def main():
|
18 |
+
st.title("Emotion Filter and Pagination App")
|
19 |
+
|
20 |
+
# Load the data
|
21 |
+
file_path = 'your_data.csv' # Ensure this is the correct path to your uploaded CSV file
|
22 |
+
df = load_data(file_path)
|
23 |
+
|
24 |
+
# Dropdown for selecting emotion
|
25 |
+
unique_emotions = ["admiration", "amusement", "anger", "annoyance", "approval",
|
26 |
+
"caring", "confusion", "curiosity", "desire", "disappointment",
|
27 |
+
"disapproval", "disgust", "embarrassment", "excitement", "fear",
|
28 |
+
"gratitude", "grief", "joy", "love", "nervousness", "optimism",
|
29 |
+
"pride", "realization", "relief", "remorse", "sadness", "surprise",
|
30 |
+
"neutral"]
|
31 |
+
selected_emotion = st.selectbox('Select Emotion', unique_emotions)
|
32 |
+
|
33 |
+
# Filter the data based on the selected emotion and sort by score
|
34 |
+
filtered_data = df[df['emotion_label'] == selected_emotion].sort_values(by='score', ascending=False).head(100)
|
35 |
+
|
36 |
+
# Pagination settings
|
37 |
+
page_size = 10
|
38 |
+
total_pages = (len(filtered_data) // page_size) + 1
|
39 |
+
page_number = st.number_input('Page number', 0, total_pages - 1, 0)
|
40 |
+
|
41 |
+
# Paginate data
|
42 |
+
paginated_data = paginate_data(filtered_data, page_number, page_size)
|
43 |
+
|
44 |
+
# Display the paginated data
|
45 |
+
st.write(f"Showing page {page_number + 1} of {total_pages}")
|
46 |
+
st.write(paginated_data)
|
47 |
+
|
48 |
+
if __name__ == "__main__":
|
49 |
+
main()
|