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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +151 -16
app.py CHANGED
@@ -1,30 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()
@@ -45,8 +170,13 @@ 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")
@@ -106,13 +236,18 @@ def main():
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()
 
 
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()
 
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")
 
236
  st.bar_chart(summary.set_index("Subject"))
237
 
238
  st.markdown("---")
239
+ st.subheader("πŸ“€ Export Options")
240
+
241
+ csv = df.to_csv(index=False).encode("utf-8")
242
+ st.download_button("⬇️ Download CSV", data=csv, file_name="study_data.csv", mime="text/csv")
243
+
244
+ if st.button("πŸ“„ Generate PDF Report"):
245
  file_path = generate_pdf(edited_df)
246
  with open(file_path, "rb") as f:
247
+ st.download_button("πŸ“₯ Download PDF", f, file_name="study_plan_report.pdf")
248
  else:
249
  st.info("No tasks added yet.")
250
 
251
  if __name__ == "__main__":
252
  main()
253
+