Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,8 @@ import streamlit as st
|
|
| 2 |
import pandas as pd
|
| 3 |
from datetime import datetime
|
| 4 |
import os
|
|
|
|
|
|
|
| 5 |
from huggingface_hub import HfApi, upload_file, list_repo_files, hf_hub_download
|
| 6 |
|
| 7 |
# Configuration for Hugging Face Repository
|
|
@@ -105,7 +107,7 @@ if "history" not in st.session_state:
|
|
| 105 |
st.session_state.current_selections = load_current_selections().to_dict(orient="records")
|
| 106 |
|
| 107 |
# Sidebar for navigating through different views
|
| 108 |
-
menu = st.sidebar.selectbox("Select View", ["Poll", "Current", "History"])
|
| 109 |
|
| 110 |
# Function to reset the current selections after submission
|
| 111 |
def reset_selections():
|
|
@@ -233,3 +235,40 @@ elif menu == "History":
|
|
| 233 |
st.table(record["Summary"])
|
| 234 |
else:
|
| 235 |
st.write("No history records found.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
from datetime import datetime
|
| 4 |
import os
|
| 5 |
+
import matplotlib.pyplot as plt
|
| 6 |
+
import seaborn as sns
|
| 7 |
from huggingface_hub import HfApi, upload_file, list_repo_files, hf_hub_download
|
| 8 |
|
| 9 |
# Configuration for Hugging Face Repository
|
|
|
|
| 107 |
st.session_state.current_selections = load_current_selections().to_dict(orient="records")
|
| 108 |
|
| 109 |
# Sidebar for navigating through different views
|
| 110 |
+
menu = st.sidebar.selectbox("Select View", ["Poll", "Current", "History", "Graph"])
|
| 111 |
|
| 112 |
# Function to reset the current selections after submission
|
| 113 |
def reset_selections():
|
|
|
|
| 235 |
st.table(record["Summary"])
|
| 236 |
else:
|
| 237 |
st.write("No history records found.")
|
| 238 |
+
|
| 239 |
+
# Graph view to display a line chart of item selections over time
|
| 240 |
+
elif menu == "Graph":
|
| 241 |
+
st.title("Breakfast Poll History - Graph View")
|
| 242 |
+
|
| 243 |
+
# Prepare data for plotting
|
| 244 |
+
if st.session_state.history:
|
| 245 |
+
history_data = []
|
| 246 |
+
for record in st.session_state.history:
|
| 247 |
+
date = record['Date']
|
| 248 |
+
for index, row in record['Summary'].iterrows():
|
| 249 |
+
for drink in row['Drinks'].split(', '):
|
| 250 |
+
history_data.append({'Date': date, 'Item': drink, 'Type': 'Drink'})
|
| 251 |
+
for food in row['Food'].split(', '):
|
| 252 |
+
history_data.append({'Date': date, 'Item': food, 'Type': 'Food'})
|
| 253 |
+
|
| 254 |
+
# Create a DataFrame from history data
|
| 255 |
+
history_df = pd.DataFrame(history_data)
|
| 256 |
+
|
| 257 |
+
# Count occurrences of each item per date
|
| 258 |
+
item_counts = history_df.groupby(['Date', 'Item']).size().reset_index(name='Count')
|
| 259 |
+
|
| 260 |
+
# Create a line plot for each item over time
|
| 261 |
+
plt.figure(figsize=(12, 6))
|
| 262 |
+
sns.lineplot(data=item_counts, x='Date', y='Count', hue='Item', marker='o')
|
| 263 |
+
|
| 264 |
+
# Customize the plot
|
| 265 |
+
plt.xticks(rotation=45)
|
| 266 |
+
plt.title('Item Selections Over Time')
|
| 267 |
+
plt.xlabel('Date')
|
| 268 |
+
plt.ylabel('Number of Selections')
|
| 269 |
+
plt.legend(loc='upper center', bbox_to_anchor=(0.5, -0.15), ncol=3)
|
| 270 |
+
|
| 271 |
+
# Display the plot
|
| 272 |
+
st.pyplot(plt.gcf())
|
| 273 |
+
else:
|
| 274 |
+
st.write("No historical data available to plot.")
|