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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +247 -32
app.py CHANGED
@@ -1,4 +1,198 @@
1
- # Smart Study Planner - FIXED VERSION
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  import streamlit as st
4
  import numpy as np
@@ -9,11 +203,11 @@ import pandas as pd
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:
@@ -54,15 +248,35 @@ class Student:
54
  return np.corrcoef(hours, marks)[0][1]
55
  return 0
56
 
 
 
 
57
  def predict_performance(self):
58
- trend = self.performance_trend()
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
 
67
  def get_grade(self, marks):
68
  if marks >= 85:
@@ -82,11 +296,12 @@ class Student:
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:
@@ -96,20 +311,21 @@ 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
 
@@ -124,22 +340,18 @@ with col2:
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("---")
@@ -159,12 +371,12 @@ if st.button("๐Ÿ“Š Analyze Performance"):
159
  avg = student.calculate_average()
160
  max_m, min_m = student.get_max_min()
161
  grade = student.get_grade(avg)
 
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)
@@ -177,18 +389,21 @@ if st.button("๐Ÿ“Š Analyze Performance"):
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()}**")
188
  st.write(f"โš  Weak Subject: **{student.weak_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"))
 
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:
20
+ # def __init__(self, name, hours, marks):
21
+ # self.name = name
22
+ # self.hours = hours
23
+ # self.marks = marks
24
+
25
+
26
+ # class Student:
27
+ # def __init__(self, name):
28
+ # self.name = name
29
+ # self.subjects = []
30
+
31
+ # def add_subject(self, subject):
32
+ # self.subjects.append(subject)
33
+
34
+ # def get_dataframe(self):
35
+ # return pd.DataFrame({
36
+ # "Subject": [s.name for s in self.subjects],
37
+ # "Study Hours": [s.hours for s in self.subjects],
38
+ # "Marks": [s.marks for s in self.subjects]
39
+ # })
40
+
41
+ # def calculate_average(self):
42
+ # marks = [s.marks for s in self.subjects]
43
+ # return np.mean(marks) if marks else 0
44
+
45
+ # def get_max_min(self):
46
+ # marks = [s.marks for s in self.subjects]
47
+ # return np.max(marks), np.min(marks)
48
+
49
+ # def performance_trend(self):
50
+ # hours = [s.hours for s in self.subjects]
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):
58
+ # trend = self.performance_trend()
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
+
67
+ # def get_grade(self, marks):
68
+ # if marks >= 85:
69
+ # return "A"
70
+ # elif marks >= 70:
71
+ # return "B"
72
+ # elif marks >= 55:
73
+ # return "C"
74
+ # elif marks >= 40:
75
+ # return "D"
76
+ # return "F"
77
+
78
+ # def best_subject(self):
79
+ # return max(self.subjects, key=lambda x: x.marks).name
80
+
81
+ # def weak_subject(self):
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
150
+
151
+ # if student is None or len(student.subjects) == 0:
152
+ # st.error("Please add subjects first!")
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()
160
+ # max_m, min_m = student.get_max_min()
161
+ # grade = student.get_grade(avg)
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()}**")
188
+ # st.write(f"โš  Weak Subject: **{student.weak_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"))
195
+ # Smart Study Planner - FINAL VERSION
196
 
197
  import streamlit as st
198
  import numpy as np
 
203
  # -------------------------------
204
  st.set_page_config(page_title="Smart Study Planner", page_icon="๐Ÿ“š", layout="centered")
205
 
206
+ st.title("๐Ÿ“š Smart Study Planner with Smart Prediction")
207
+ st.markdown("Analyze your study habits and improve performance ๐Ÿš€")
208
 
209
  # -------------------------------
210
+ # CLASSES (OOP)
211
  # -------------------------------
212
 
213
  class Subject:
 
248
  return np.corrcoef(hours, marks)[0][1]
249
  return 0
250
 
251
+ # -------------------------------
252
+ # AI-STYLE SMART PREDICTION
253
+ # -------------------------------
254
  def predict_performance(self):
255
+ hours = np.array([s.hours for s in self.subjects])
256
+ marks = np.array([s.marks for s in self.subjects])
257
 
258
+ if len(hours) == 0:
259
+ return 0
 
260
 
261
+ avg_marks = np.mean(marks)
262
+ avg_hours = np.mean(hours)
263
+
264
+ # Trend (relationship between hours and marks)
265
+ if len(hours) > 1:
266
+ trend = np.corrcoef(hours, marks)[0][1]
267
+ else:
268
+ trend = 0
269
+
270
+ # Consistency (low variance = better)
271
+ consistency = 1 / (1 + np.var(marks))
272
+
273
+ # Smart prediction formula
274
+ predicted = avg_marks \
275
+ + (avg_hours * 1.5) \
276
+ + (trend * 10) \
277
+ + (consistency * 5)
278
+
279
+ return min(predicted, 100)
280
 
281
  def get_grade(self, marks):
282
  if marks >= 85:
 
296
  return min(self.subjects, key=lambda x: x.marks).name
297
 
298
  def suggest_improvement(self):
299
+ weak = self.weak_subject()
300
+ return f"Focus more on {weak} and increase study hours by at least 2 hours."
301
 
302
 
303
  # -------------------------------
304
+ # SESSION STATE (FIXED LOGIC)
305
  # -------------------------------
306
 
307
  if "student" not in st.session_state:
 
311
  st.session_state.student_name = ""
312
 
313
  # -------------------------------
314
+ # INPUT SECTION
315
  # -------------------------------
316
 
317
  st.subheader("๐Ÿ‘ค Student Information")
318
 
319
  name = st.text_input("Enter Student Name", value=st.session_state.student_name)
320
 
321
+ # FIX: create new student when name changes
322
+ if name != st.session_state.student_name:
323
  st.session_state.student_name = name
324
+ st.session_state.student = Student(name)
325
 
326
+ # -------------------------------
327
+ # ADD SUBJECT
328
+ # -------------------------------
 
329
 
330
  st.subheader("๐Ÿ“˜ Add Subject")
331
 
 
340
  with col3:
341
  marks = st.number_input("Marks", min_value=0, max_value=100)
342
 
 
 
 
 
343
  if st.button("โž• Add Subject"):
344
+ if not name:
345
+ st.error("Please enter student name first!")
346
+ elif not subject_name:
347
+ st.error("Please enter subject name!")
348
  else:
349
  sub = Subject(subject_name, hours, marks)
350
  st.session_state.student.add_subject(sub)
351
  st.success(f"{subject_name} added successfully!")
352
 
353
  # -------------------------------
354
+ # ANALYSIS SECTION
355
  # -------------------------------
356
 
357
  st.markdown("---")
 
371
  avg = student.calculate_average()
372
  max_m, min_m = student.get_max_min()
373
  grade = student.get_grade(avg)
374
+
375
  predicted = student.predict_performance()
376
  predicted_grade = student.get_grade(predicted)
377
 
378
  # ---------------- METRICS ----------------
379
  col1, col2, col3 = st.columns(3)
 
380
  col1.metric("Average Marks", f"{avg:.2f}")
381
  col2.metric("Highest Marks", max_m)
382
  col3.metric("Lowest Marks", min_m)
 
389
 
390
  # ---------------- PREDICTION ----------------
391
  st.subheader("๐Ÿ”ฎ Smart Prediction")
392
+ st.success(f"Expected Marks: {predicted:.2f}")
 
393
  st.success(f"Predicted Grade: {predicted_grade}")
394
 
395
+ # ---------------- EXTRA INSIGHTS ----------------
396
  st.subheader("๐Ÿ“Œ Insights")
 
397
  st.write(f"๐Ÿ† Best Subject: **{student.best_subject()}**")
398
  st.write(f"โš  Weak Subject: **{student.weak_subject()}**")
399
 
400
  st.info(student.suggest_improvement())
401
 
402
+ # ---------------- CONSISTENCY SCORE ----------------
403
+ marks_list = [s.marks for s in student.subjects]
404
+ consistency_score = 1 / (1 + np.var(marks_list))
405
+ st.write(f"๐Ÿ“Š Consistency Score: {round(consistency_score, 2)}")
406
+
407
  # ---------------- CHART ----------------
408
  st.subheader("๐Ÿ“‰ Study vs Performance Trend")
409
  st.line_chart(df.set_index("Subject"))