Spaces:
Running
Running
MarcosRodrigo
commited on
Commit
•
5f7ff4f
1
Parent(s):
8218595
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,41 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
from datetime import datetime
|
|
|
4 |
|
5 |
# Initialize session state for temporary and historical storage
|
6 |
if "users" not in st.session_state:
|
7 |
st.session_state.users = []
|
8 |
if "current_selections" not in st.session_state:
|
9 |
st.session_state.current_selections = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
if "history" not in st.session_state:
|
11 |
-
st.session_state.history =
|
12 |
|
13 |
# Sidebar for navigating through different views
|
14 |
menu = st.sidebar.selectbox("Select View", ["Poll", "History"])
|
@@ -66,9 +93,13 @@ if menu == "Poll":
|
|
66 |
st.table(df)
|
67 |
|
68 |
if st.button("Submit Summary"):
|
69 |
-
# Save the current summary to
|
|
|
|
|
|
|
70 |
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
71 |
st.session_state.history.append({"Date": timestamp, "Summary": df})
|
|
|
72 |
st.success(f"Summary submitted at {timestamp}")
|
73 |
reset_selections()
|
74 |
st.session_state.step = 1
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
from datetime import datetime
|
4 |
+
import os
|
5 |
|
6 |
# Initialize session state for temporary and historical storage
|
7 |
if "users" not in st.session_state:
|
8 |
st.session_state.users = []
|
9 |
if "current_selections" not in st.session_state:
|
10 |
st.session_state.current_selections = []
|
11 |
+
|
12 |
+
# Directory to store history
|
13 |
+
history_dir = "history"
|
14 |
+
if not os.path.exists(history_dir):
|
15 |
+
os.makedirs(history_dir)
|
16 |
+
|
17 |
+
# Load history from existing text files
|
18 |
+
def load_history():
|
19 |
+
history = []
|
20 |
+
for filename in os.listdir(history_dir):
|
21 |
+
if filename.endswith(".txt"):
|
22 |
+
date = filename.split(".txt")[0]
|
23 |
+
filepath = os.path.join(history_dir, filename)
|
24 |
+
with open(filepath, "r") as file:
|
25 |
+
content = file.read()
|
26 |
+
summary_df = pd.read_csv(filepath)
|
27 |
+
history.append({"Date": date, "Summary": summary_df})
|
28 |
+
return history
|
29 |
+
|
30 |
+
# Save current summary to a text file
|
31 |
+
def save_summary_to_file(summary_df):
|
32 |
+
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
|
33 |
+
filepath = os.path.join(history_dir, f"{timestamp}.txt")
|
34 |
+
summary_df.to_csv(filepath, index=False)
|
35 |
+
|
36 |
+
# Load history into session state
|
37 |
if "history" not in st.session_state:
|
38 |
+
st.session_state.history = load_history()
|
39 |
|
40 |
# Sidebar for navigating through different views
|
41 |
menu = st.sidebar.selectbox("Select View", ["Poll", "History"])
|
|
|
93 |
st.table(df)
|
94 |
|
95 |
if st.button("Submit Summary"):
|
96 |
+
# Save the current summary to a text file in the history directory
|
97 |
+
save_summary_to_file(df)
|
98 |
+
|
99 |
+
# Add to session state history
|
100 |
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
101 |
st.session_state.history.append({"Date": timestamp, "Summary": df})
|
102 |
+
|
103 |
st.success(f"Summary submitted at {timestamp}")
|
104 |
reset_selections()
|
105 |
st.session_state.step = 1
|