ilsa15 commited on
Commit
4f4d286
Β·
verified Β·
1 Parent(s): 44a9429

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -155
app.py CHANGED
@@ -1,156 +1,17 @@
1
- # import streamlit as st
2
- # import pandas as pd
3
- # import os
4
- # from fpdf import FPDF
5
- # import datetime
6
-
7
- # DATA_FILE = "study_data.csv"
8
- # CALENDAR_FILE = "calendar_data.csv"
9
-
10
- # # Load or initialize data
11
- # def load_data():
12
- # if os.path.exists(DATA_FILE):
13
- # return pd.read_csv(DATA_FILE)
14
- # else:
15
- # return pd.DataFrame(columns=["Subject", "Topic", "Goal", "Progress (%)"])
16
-
17
- # def save_data(df):
18
- # df.to_csv(DATA_FILE, index=False)
19
-
20
- # def load_calendar():
21
- # if os.path.exists(CALENDAR_FILE):
22
- # return pd.read_csv(CALENDAR_FILE)
23
- # else:
24
- # return pd.DataFrame(columns=["Day", "Planned Topic"])
25
-
26
- # def save_calendar(df):
27
- # df.to_csv(CALENDAR_FILE, index=False)
28
-
29
- # def generate_pdf(df):
30
- # pdf = FPDF()
31
- # pdf.add_page()
32
- # pdf.set_font("Arial", size=12)
33
- # pdf.cell(200, 10, txt="Study Plan Report", ln=True, align='C')
34
- # pdf.ln(10)
35
-
36
- # for i, row in df.iterrows():
37
- # pdf.multi_cell(0, 10, f"Subject: {row['Subject']}\nTopic: {row['Topic']}\nGoal: {row['Goal']}\nProgress: {row['Progress (%)']}%\n")
38
- # pdf.ln(1)
39
-
40
- # file_path = "study_report.pdf"
41
- # pdf.output(file_path)
42
- # return file_path
43
-
44
- # def main():
45
- # st.set_page_config(page_title="Study Planner", layout="wide")
46
- # st.title("πŸ“š Course Organizer & Study Planner")
47
-
48
- # df = load_data()
49
- # calendar_df = load_calendar()
50
-
51
- # with st.sidebar:
52
- # st.header("βž• Add Study Task")
53
- # subject = st.text_input("Subject")
54
- # topic = st.text_input("Topic")
55
- # goal = st.text_area("Goal Description")
56
- # progress = st.slider("Progress (%)", 0, 100, 0)
57
-
58
- # if st.button("Add Task"):
59
- # if subject and topic:
60
- # new_row = {"Subject": subject, "Topic": topic, "Goal": goal, "Progress (%)": progress}
61
- # df = pd.concat([df, pd.DataFrame([new_row])], ignore_index=True)
62
- # save_data(df)
63
- # st.success("Task added!")
64
- # else:
65
- # st.error("Subject and Topic are required.")
66
-
67
- # st.subheader("🎯 Study Summary by Subject")
68
- # if not df.empty:
69
- # subjects = df["Subject"].unique()
70
- # cols = st.columns(len(subjects))
71
- # colors = ["#fca311", "#a1c181", "#f28482", "#8ecae6", "#ffb703"]
72
-
73
- # for i, subject in enumerate(subjects):
74
- # sub_df = df[df["Subject"] == subject]
75
- # avg_progress = int(sub_df["Progress (%)"].mean())
76
- # with cols[i % len(cols)]:
77
- # st.markdown(f"""
78
- # <div style='padding: 1em; border-radius: 10px; background-color: {colors[i % len(colors)]}; color: black'>
79
- # <h4>{subject}</h4>
80
- # <p>Topics: {len(sub_df)}</p>
81
- # <p>Avg. Progress: {avg_progress}%</p>
82
- # </div>
83
- # """, unsafe_allow_html=True)
84
-
85
- # st.subheader("πŸ“… Weekly Study Calendar")
86
- # days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
87
- # calendar_data = []
88
- # for day in days:
89
- # topic = st.text_input(f"{day}", value=calendar_df.set_index("Day").get("Planned Topic", {}).get(day, ""))
90
- # calendar_data.append({"Day": day, "Planned Topic": topic})
91
-
92
- # if st.button("Save Weekly Plan"):
93
- # calendar_df = pd.DataFrame(calendar_data)
94
- # save_calendar(calendar_df)
95
- # st.success("Weekly calendar saved.")
96
-
97
- # st.markdown("---")
98
- # st.subheader("πŸ“‹ All Study Tasks (Editable)")
99
- # if not df.empty:
100
- # edited_df = st.data_editor(df, num_rows="dynamic", use_container_width=True)
101
- # save_data(edited_df)
102
-
103
- # st.markdown("---")
104
- # st.subheader("πŸ“Š Progress Summary")
105
- # summary = edited_df.groupby("Subject")["Progress (%)"].mean().reset_index()
106
- # st.bar_chart(summary.set_index("Subject"))
107
-
108
- # st.markdown("---")
109
- # st.subheader("πŸ“€ Download Study Plan Report")
110
- # if st.button("Generate PDF Report"):
111
- # file_path = generate_pdf(edited_df)
112
- # with open(file_path, "rb") as f:
113
- # st.download_button("πŸ“„ Download PDF", f, file_name="study_plan_report.pdf")
114
- # else:
115
- # st.info("No tasks added yet.")
116
-
117
- # if __name__ == "__main__":
118
- # main()
119
-
120
-
121
  import streamlit as st
122
  import pandas as pd
123
- import os
124
  from fpdf import FPDF
125
  import datetime
126
  import io
127
 
128
- DEFAULT_FILE = "study_data.csv"
129
- DEFAULT_CALENDAR = "calendar_data.csv"
130
-
131
- # Load default or uploaded data
132
- def load_data(uploaded_file):
133
- if uploaded_file:
134
- return pd.read_csv(uploaded_file)
135
- elif os.path.exists(DEFAULT_FILE):
136
- return pd.read_csv(DEFAULT_FILE)
137
- else:
138
- return pd.DataFrame(columns=["Subject", "Topic", "Goal", "Progress (%)"])
139
-
140
- def save_data(df):
141
- df.to_csv(DEFAULT_FILE, index=False)
142
-
143
- def load_calendar(uploaded_file):
144
- if uploaded_file:
145
- return pd.read_csv(uploaded_file)
146
- elif os.path.exists(DEFAULT_CALENDAR):
147
- return pd.read_csv(DEFAULT_CALENDAR)
148
- else:
149
- return pd.DataFrame(columns=["Day", "Planned Topic"])
150
-
151
- def save_calendar(df):
152
- df.to_csv(DEFAULT_CALENDAR, index=False)
153
 
 
154
  def generate_pdf(df):
155
  pdf = FPDF()
156
  pdf.add_page()
@@ -170,13 +31,18 @@ def main():
170
  st.set_page_config(page_title="Study Planner", layout="wide")
171
  st.title("πŸ“š Course Organizer & Study Planner")
172
 
 
 
173
  st.sidebar.markdown("---")
174
  st.sidebar.header("πŸ“‚ Upload Your Study Plan")
175
  uploaded_plan = st.sidebar.file_uploader("Upload Study CSV", type=["csv"])
176
  uploaded_calendar = st.sidebar.file_uploader("Upload Calendar CSV", type=["csv"])
177
 
178
- df = load_data(uploaded_plan)
179
- calendar_df = load_calendar(uploaded_calendar)
 
 
 
180
 
181
  with st.sidebar:
182
  st.header("βž• Add Study Task")
@@ -188,12 +54,17 @@ def main():
188
  if st.button("Add Task"):
189
  if subject and topic:
190
  new_row = {"Subject": subject, "Topic": topic, "Goal": goal, "Progress (%)": progress}
191
- df = pd.concat([df, pd.DataFrame([new_row])], ignore_index=True)
192
- save_data(df)
 
 
193
  st.success("Task added!")
194
  else:
195
  st.error("Subject and Topic are required.")
196
 
 
 
 
197
  st.subheader("🎯 Study Summary by Subject")
198
  if not df.empty:
199
  subjects = df["Subject"].unique()
@@ -216,19 +87,19 @@ def main():
216
  days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
217
  calendar_data = []
218
  for day in days:
219
- topic = st.text_input(f"{day}", value=calendar_df.set_index("Day").get("Planned Topic", {}).get(day, ""))
 
220
  calendar_data.append({"Day": day, "Planned Topic": topic})
221
 
222
  if st.button("Save Weekly Plan"):
223
- calendar_df = pd.DataFrame(calendar_data)
224
- save_calendar(calendar_df)
225
  st.success("Weekly calendar saved.")
226
 
227
  st.markdown("---")
228
  st.subheader("πŸ“‹ All Study Tasks (Editable)")
229
  if not df.empty:
230
  edited_df = st.data_editor(df, num_rows="dynamic", use_container_width=True)
231
- save_data(edited_df)
232
 
233
  st.markdown("---")
234
  st.subheader("πŸ“Š Progress Summary")
@@ -250,4 +121,3 @@ def main():
250
 
251
  if __name__ == "__main__":
252
  main()
253
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  import pandas as pd
 
3
  from fpdf import FPDF
4
  import datetime
5
  import io
6
 
7
+ # Initialize session state
8
+ def init_session_state():
9
+ if "study_data" not in st.session_state:
10
+ st.session_state.study_data = pd.DataFrame(columns=["Subject", "Topic", "Goal", "Progress (%)"])
11
+ if "calendar_data" not in st.session_state:
12
+ st.session_state.calendar_data = pd.DataFrame({"Day": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"], "Planned Topic": ["" for _ in range(7)]})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
+ # PDF Generation
15
  def generate_pdf(df):
16
  pdf = FPDF()
17
  pdf.add_page()
 
31
  st.set_page_config(page_title="Study Planner", layout="wide")
32
  st.title("πŸ“š Course Organizer & Study Planner")
33
 
34
+ init_session_state()
35
+
36
  st.sidebar.markdown("---")
37
  st.sidebar.header("πŸ“‚ Upload Your Study Plan")
38
  uploaded_plan = st.sidebar.file_uploader("Upload Study CSV", type=["csv"])
39
  uploaded_calendar = st.sidebar.file_uploader("Upload Calendar CSV", type=["csv"])
40
 
41
+ # Handle uploads
42
+ if uploaded_plan:
43
+ st.session_state.study_data = pd.read_csv(uploaded_plan)
44
+ if uploaded_calendar:
45
+ st.session_state.calendar_data = pd.read_csv(uploaded_calendar)
46
 
47
  with st.sidebar:
48
  st.header("βž• Add Study Task")
 
54
  if st.button("Add Task"):
55
  if subject and topic:
56
  new_row = {"Subject": subject, "Topic": topic, "Goal": goal, "Progress (%)": progress}
57
+ st.session_state.study_data = pd.concat([
58
+ st.session_state.study_data,
59
+ pd.DataFrame([new_row])
60
+ ], ignore_index=True)
61
  st.success("Task added!")
62
  else:
63
  st.error("Subject and Topic are required.")
64
 
65
+ df = st.session_state.study_data
66
+ calendar_df = st.session_state.calendar_data
67
+
68
  st.subheader("🎯 Study Summary by Subject")
69
  if not df.empty:
70
  subjects = df["Subject"].unique()
 
87
  days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
88
  calendar_data = []
89
  for day in days:
90
+ default_topic = calendar_df.set_index("Day").get("Planned Topic", {}).get(day, "")
91
+ topic = st.text_input(f"{day}", value=default_topic)
92
  calendar_data.append({"Day": day, "Planned Topic": topic})
93
 
94
  if st.button("Save Weekly Plan"):
95
+ st.session_state.calendar_data = pd.DataFrame(calendar_data)
 
96
  st.success("Weekly calendar saved.")
97
 
98
  st.markdown("---")
99
  st.subheader("πŸ“‹ All Study Tasks (Editable)")
100
  if not df.empty:
101
  edited_df = st.data_editor(df, num_rows="dynamic", use_container_width=True)
102
+ st.session_state.study_data = edited_df
103
 
104
  st.markdown("---")
105
  st.subheader("πŸ“Š Progress Summary")
 
121
 
122
  if __name__ == "__main__":
123
  main()