syeda-Rija20 commited on
Commit
0a9f311
ยท
verified ยท
1 Parent(s): 8e920f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -59
app.py CHANGED
@@ -1,19 +1,19 @@
1
- # Smart Study Planner - Enhanced Version
2
 
3
  import streamlit as st
4
  import numpy as np
5
  import pandas as pd
6
 
7
  # -------------------------------
8
- # PAGE CONFIG (Better UI)
9
  # -------------------------------
10
  st.set_page_config(page_title="Smart Study Planner", page_icon="๐Ÿ“š", layout="centered")
11
 
12
- st.title("๐Ÿ“š Smart Study Planner with AI Prediction")
13
- st.markdown("Analyze your study habits and improve performance ๐Ÿš€")
14
 
15
  # -------------------------------
16
- # CLASSES (OOP)
17
  # -------------------------------
18
 
19
  class Subject:
@@ -51,7 +51,7 @@ class Student:
51
  marks = [s.marks for s in self.subjects]
52
 
53
  if len(hours) > 1:
54
- return np.corrcoef(hours, marks)[0][1] # correlation
55
  return 0
56
 
57
  def predict_performance(self):
@@ -59,8 +59,8 @@ class Student:
59
  predicted = []
60
 
61
  for s in self.subjects:
62
- improvement = (2 * 4) + (trend * 5) # smarter logic
63
- predicted.append(min(s.marks + improvement, 100))
64
 
65
  return np.mean(predicted) if predicted else 0
66
 
@@ -82,57 +82,68 @@ class Student:
82
  return min(self.subjects, key=lambda x: x.marks).name
83
 
84
  def suggest_improvement(self):
85
- weak = self.weak_subject()
86
- return f"Focus more on {weak} and increase study hours by at least 2 hours."
87
 
88
 
89
  # -------------------------------
90
- # SESSION STATE
91
  # -------------------------------
 
92
  if "student" not in st.session_state:
93
  st.session_state.student = None
94
 
 
 
 
95
  # -------------------------------
96
- # INPUT SECTION (Styled)
97
  # -------------------------------
98
 
99
- with st.container():
100
- st.subheader("๐Ÿ‘ค Student Details")
 
101
 
102
- name = st.text_input("Enter Student Name")
 
103
 
104
- if name:
 
105
  st.session_state.student = Student(name)
106
 
107
- with st.container():
108
- st.subheader("๐Ÿ“˜ Add Subject")
109
 
110
- col1, col2, col3 = st.columns(3)
 
 
 
 
 
111
 
112
- with col1:
113
- subject_name = st.text_input("Subject")
114
 
115
- with col2:
116
- hours = st.number_input("Study Hours", min_value=0.0, step=0.5)
117
 
118
- with col3:
119
- marks = st.number_input("Marks", min_value=0, max_value=100)
 
120
 
121
- if st.button("โž• Add Subject"):
122
- if not subject_name:
123
- st.error("Enter subject name!")
124
- elif st.session_state.student is None:
125
- st.error("Enter student name first!")
126
- else:
127
- sub = Subject(subject_name, hours, marks)
128
- st.session_state.student.add_subject(sub)
129
- st.success(f"{subject_name} added successfully!")
130
 
131
  # -------------------------------
132
- # ANALYSIS SECTION
133
  # -------------------------------
134
 
135
  st.markdown("---")
 
136
  if st.button("๐Ÿ“Š Analyze Performance"):
137
 
138
  student = st.session_state.student
@@ -142,7 +153,7 @@ if st.button("๐Ÿ“Š Analyze Performance"):
142
  else:
143
  df = student.get_dataframe()
144
 
145
- st.subheader("๐Ÿ“‹ Subject Data")
146
  st.dataframe(df, use_container_width=True)
147
 
148
  avg = student.calculate_average()
@@ -151,36 +162,26 @@ if st.button("๐Ÿ“Š Analyze Performance"):
151
  predicted = student.predict_performance()
152
  predicted_grade = student.get_grade(predicted)
153
 
154
- # -------------------------------
155
- # METRICS UI
156
- # -------------------------------
157
  col1, col2, col3 = st.columns(3)
158
 
159
- col1.metric("Average", f"{avg:.2f}")
160
- col2.metric("Highest", max_m)
161
- col3.metric("Lowest", min_m)
162
 
163
- # -------------------------------
164
- # PROGRESS BAR (NEW FEATURE)
165
- # -------------------------------
166
  st.subheader("๐Ÿ“ˆ Performance Progress")
167
  st.progress(int(avg))
168
 
169
  st.write(f"๐ŸŽฏ Current Grade: **{grade}**")
170
 
171
- # -------------------------------
172
- # SMART PREDICTION
173
- # -------------------------------
174
  st.subheader("๐Ÿ”ฎ Smart Prediction")
175
 
176
- st.write(f"If you study 2 more hours daily:")
177
-
178
- st.success(f"๐Ÿ“Š Expected Marks: {predicted:.2f}")
179
- st.success(f"๐Ÿ† Predicted Grade: {predicted_grade}")
180
 
181
- # -------------------------------
182
- # INSIGHTS
183
- # -------------------------------
184
  st.subheader("๐Ÿ“Œ Insights")
185
 
186
  st.write(f"๐Ÿ† Best Subject: **{student.best_subject()}**")
@@ -188,8 +189,6 @@ if st.button("๐Ÿ“Š Analyze Performance"):
188
 
189
  st.info(student.suggest_improvement())
190
 
191
- # -------------------------------
192
- # CHART
193
- # -------------------------------
194
- st.subheader("๐Ÿ“‰ Study Trend")
195
  st.line_chart(df.set_index("Subject"))
 
1
+ # Smart Study Planner - FIXED VERSION
2
 
3
  import streamlit as st
4
  import numpy as np
5
  import pandas as pd
6
 
7
  # -------------------------------
8
+ # PAGE CONFIG
9
  # -------------------------------
10
  st.set_page_config(page_title="Smart Study Planner", page_icon="๐Ÿ“š", layout="centered")
11
 
12
+ st.title("๐Ÿ“š Smart Study Planner with Performance Prediction")
13
+ st.markdown("Track your study progress and predict performance smartly ๐Ÿš€")
14
 
15
  # -------------------------------
16
+ # OOP CLASSES
17
  # -------------------------------
18
 
19
  class Subject:
 
51
  marks = [s.marks for s in self.subjects]
52
 
53
  if len(hours) > 1:
54
+ return np.corrcoef(hours, marks)[0][1]
55
  return 0
56
 
57
  def predict_performance(self):
 
59
  predicted = []
60
 
61
  for s in self.subjects:
62
+ boost = (2 * 4) + (trend * 5) # smart logic
63
+ predicted.append(min(s.marks + boost, 100))
64
 
65
  return np.mean(predicted) if predicted else 0
66
 
 
82
  return min(self.subjects, key=lambda x: x.marks).name
83
 
84
  def suggest_improvement(self):
85
+ return f"Focus more on {self.weak_subject()} and increase study time by 2 hours."
 
86
 
87
 
88
  # -------------------------------
89
+ # SESSION STATE FIX (IMPORTANT)
90
  # -------------------------------
91
+
92
  if "student" not in st.session_state:
93
  st.session_state.student = None
94
 
95
+ if "student_name" not in st.session_state:
96
+ st.session_state.student_name = ""
97
+
98
  # -------------------------------
99
+ # INPUT UI
100
  # -------------------------------
101
 
102
+ st.subheader("๐Ÿ‘ค Student Information")
103
+
104
+ name = st.text_input("Enter Student Name", value=st.session_state.student_name)
105
 
106
+ if name:
107
+ st.session_state.student_name = name
108
 
109
+ # FIX: only create once
110
+ if st.session_state.student is None:
111
  st.session_state.student = Student(name)
112
 
 
 
113
 
114
+ st.subheader("๐Ÿ“˜ Add Subject")
115
+
116
+ col1, col2, col3 = st.columns(3)
117
+
118
+ with col1:
119
+ subject_name = st.text_input("Subject")
120
 
121
+ with col2:
122
+ hours = st.number_input("Study Hours", min_value=0.0, step=0.5)
123
 
124
+ with col3:
125
+ marks = st.number_input("Marks", min_value=0, max_value=100)
126
 
127
+ # -------------------------------
128
+ # ADD SUBJECT
129
+ # -------------------------------
130
 
131
+ if st.button("โž• Add Subject"):
132
+ if not subject_name:
133
+ st.error("Please enter subject name")
134
+ elif st.session_state.student is None:
135
+ st.error("Please enter student name first")
136
+ else:
137
+ sub = Subject(subject_name, hours, marks)
138
+ st.session_state.student.add_subject(sub)
139
+ st.success(f"{subject_name} added successfully!")
140
 
141
  # -------------------------------
142
+ # ANALYSIS
143
  # -------------------------------
144
 
145
  st.markdown("---")
146
+
147
  if st.button("๐Ÿ“Š Analyze Performance"):
148
 
149
  student = st.session_state.student
 
153
  else:
154
  df = student.get_dataframe()
155
 
156
+ st.subheader("๐Ÿ“‹ Performance Table")
157
  st.dataframe(df, use_container_width=True)
158
 
159
  avg = student.calculate_average()
 
162
  predicted = student.predict_performance()
163
  predicted_grade = student.get_grade(predicted)
164
 
165
+ # ---------------- METRICS ----------------
 
 
166
  col1, col2, col3 = st.columns(3)
167
 
168
+ col1.metric("Average Marks", f"{avg:.2f}")
169
+ col2.metric("Highest Marks", max_m)
170
+ col3.metric("Lowest Marks", min_m)
171
 
172
+ # ---------------- PROGRESS BAR ----------------
 
 
173
  st.subheader("๐Ÿ“ˆ Performance Progress")
174
  st.progress(int(avg))
175
 
176
  st.write(f"๐ŸŽฏ Current Grade: **{grade}**")
177
 
178
+ # ---------------- PREDICTION ----------------
 
 
179
  st.subheader("๐Ÿ”ฎ Smart Prediction")
180
 
181
+ st.success(f"Expected Marks (if improved): {predicted:.2f}")
182
+ st.success(f"Predicted Grade: {predicted_grade}")
 
 
183
 
184
+ # ---------------- INSIGHTS ----------------
 
 
185
  st.subheader("๐Ÿ“Œ Insights")
186
 
187
  st.write(f"๐Ÿ† Best Subject: **{student.best_subject()}**")
 
189
 
190
  st.info(student.suggest_improvement())
191
 
192
+ # ---------------- CHART ----------------
193
+ st.subheader("๐Ÿ“‰ Study vs Performance Trend")
 
 
194
  st.line_chart(df.set_index("Subject"))