File size: 5,170 Bytes
c9bfbdd
 
 
 
 
4f4d286
 
 
 
 
 
c9bfbdd
4f4d286
c9bfbdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78d2ba7
c9bfbdd
4f4d286
 
44a9429
78d2ba7
44a9429
 
 
4f4d286
 
 
 
 
c9bfbdd
78d2ba7
 
 
 
 
c9bfbdd
 
 
 
 
 
 
 
 
 
4f4d286
 
 
 
c9bfbdd
 
 
 
4f4d286
 
 
c9bfbdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4f4d286
 
c9bfbdd
 
 
4f4d286
c9bfbdd
 
 
 
 
 
4f4d286
c9bfbdd
 
 
 
 
 
 
44a9429
 
 
 
 
 
c9bfbdd
 
44a9429
c9bfbdd
 
 
 
 
78d2ba7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import streamlit as st
import pandas as pd
from fpdf import FPDF
import datetime

# Initialize session state
def init_session_state():
    if "study_data" not in st.session_state:
        st.session_state.study_data = pd.DataFrame(columns=["Subject", "Topic", "Goal", "Progress (%)"])
    if "calendar_data" not in st.session_state:
        st.session_state.calendar_data = pd.DataFrame({"Day": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"], "Planned Topic": ["" for _ in range(7)]})

# PDF Generation
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("πŸ“š Smart Study Planner")

    init_session_state()

    st.sidebar.markdown("---")
    st.sidebar.header("πŸ“‚ Upload Your Study Plan (optional)")
    uploaded_plan = st.sidebar.file_uploader("Upload Study CSV", type=["csv"])
    uploaded_calendar = st.sidebar.file_uploader("Upload Calendar CSV", type=["csv"])

    # Handle uploads
    if uploaded_plan:
        st.session_state.study_data = pd.read_csv(uploaded_plan)
    if uploaded_calendar:
        st.session_state.calendar_data = pd.read_csv(uploaded_calendar)

    if st.sidebar.button("πŸ” Reset All"):
        st.session_state.study_data = pd.DataFrame(columns=["Subject", "Topic", "Goal", "Progress (%)"])
        st.session_state.calendar_data = pd.DataFrame({"Day": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"], "Planned Topic": ["" for _ in range(7)]})
        st.sidebar.success("Planner has been reset.")

    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}
                st.session_state.study_data = pd.concat([
                    st.session_state.study_data,
                    pd.DataFrame([new_row])
                ], ignore_index=True)
                st.success("Task added!")
            else:
                st.error("Subject and Topic are required.")

    df = st.session_state.study_data
    calendar_df = st.session_state.calendar_data

    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:
        default_topic = calendar_df.set_index("Day").get("Planned Topic", {}).get(day, "")
        topic = st.text_input(f"{day}", value=default_topic)
        calendar_data.append({"Day": day, "Planned Topic": topic})

    if st.button("Save Weekly Plan"):
        st.session_state.calendar_data = pd.DataFrame(calendar_data)
        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)
        st.session_state.study_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("πŸ“€ Export Options")

        csv = df.to_csv(index=False).encode("utf-8")
        st.download_button("⬇️ Download CSV", data=csv, file_name="study_data.csv", mime="text/csv")

        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()