Spaces:
Sleeping
Sleeping
Create app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118import streamlit as stimport pandas as pdimport osfrom fpdf import FPDFimport datetime
DATA_FILE = "study_data.csv"CALENDAR_FILE = "calendar_data.csv"
# Load or initialize datadef load_data(): if os.path.exists(DATA_FILE): return pd.read_csv(DATA_FILE) else: return pd.DataFrame(columns=["Subject", "Topic", "Goal", "Progress (%)"])
def save_data(df): df.to_csv(DATA_FILE, index=False)
def load_calendar(): if os.path.exists(CALENDAR_FILE): return pd.read_csv(CALENDAR_FILE) else: return pd.DataFrame(columns=["Day", "Planned Topic"])
def save_calendar(df): df.to_csv(CALENDAR_FILE, index=False)
def generate_pdf(df): pdf = FPDF() pdf.add_page() pdf.set_font("Arial", size=12) pdf.cell(200, 10, txt="Study Plan Report", ln=True, align='C') pdf.ln(10)
for i, row in df.iterrows(): pdf.multi_cell(0, 10, f"Subject: {row['Subject']}\nTopic: {row['Topic']}\nGoal: {row['Goal']}\nProgress: {row['Progress (%)']}%\n") pdf.ln(1)
file_path = "study_report.pdf" pdf.output(file_path) return file_path
def main(): st.set_page_config(page_title="Study Planner", layout="wide") st.title("π Course Organizer & Study Planner")
df = load_data() calendar_df = load_calendar()
with st.sidebar: st.header("β Add Study Task") subject = st.text_input("Subject") topic = st.text_input("Topic") goal = st.text_area("Goal Description") progress = st.slider("Progress (%)", 0, 100, 0)
if st.button("Add Task"): if subject and topic: new_row = {"Subject": subject, "Topic": topic, "Goal": goal, "Progress (%)": progress} df = pd.concat([df, pd.DataFrame([new_row])], ignore_index=True) save_data(df) st.success("Task added!") else: st.error("Subject and Topic are required.")
st.subheader("π― Study Summary by Subject") if not df.empty: subjects = df["Subject"].unique() cols = st.columns(len(subjects)) colors = ["#fca311", "#a1c181", "#f28482", "#8ecae6", "#ffb703"]
for i, subject in enumerate(subjects): sub_df = df[df["Subject"] == subject] avg_progress = int(sub_df["Progress (%)"].mean()) with cols[i % len(cols)]: st.markdown(f""" <div style='padding: 1em; border-radius: 10px; background-color: {colors[i % len(colors)]}; color: black'> <h4>{subject}</h4> <p>Topics: {len(sub_df)}</p> <p>Avg. Progress: {avg_progress}%</p> </div> """, unsafe_allow_html=True)
st.subheader("π
Weekly Study Calendar") days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] calendar_data = [] for day in days: topic = st.text_input(f"{day}", value=calendar_df.set_index("Day").get("Planned Topic", {}).get(day, "")) calendar_data.append({"Day": day, "Planned Topic": topic})
if st.button("Save Weekly Plan"): calendar_df = pd.DataFrame(calendar_data) save_calendar(calendar_df) st.success("Weekly calendar saved.")
st.markdown("---") st.subheader("π All Study Tasks (Editable)") if not df.empty: edited_df = st.data_editor(df, num_rows="dynamic", use_container_width=True) save_data(edited_df)
st.markdown("---") st.subheader("π Progress Summary") summary = edited_df.groupby("Subject")["Progress (%)"].mean().reset_index() st.bar_chart(summary.set_index("Subject"))
st.markdown("---") st.subheader("π€ Download Study Plan Report") if st.button("Generate PDF Report"): file_path = generate_pdf(edited_df) with open(file_path, "rb") as f: st.download_button("π Download PDF", f, file_name="study_plan_report.pdf") else: st.info("No tasks added yet.")
if __name__ == "__main__": main()app.pyAdded+118