Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|