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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +117 -87
app.py CHANGED
@@ -1,17 +1,25 @@
1
- # Smart Study Planner with Performance Prediction
2
 
3
  import streamlit as st
4
  import numpy as np
5
  import pandas as pd
6
 
7
  # -------------------------------
8
- # OOP CLASSES
 
 
 
 
 
 
 
 
9
  # -------------------------------
10
 
11
  class Subject:
12
- def __init__(self, name, study_hours, marks):
13
  self.name = name
14
- self.study_hours = study_hours
15
  self.marks = marks
16
 
17
 
@@ -23,32 +31,38 @@ class Student:
23
  def add_subject(self, subject):
24
  self.subjects.append(subject)
25
 
26
- def get_data(self):
27
- data = {
28
- "Subject": [],
29
- "Study Hours": [],
30
- "Marks": []
31
- }
32
- for sub in self.subjects:
33
- data["Subject"].append(sub.name)
34
- data["Study Hours"].append(sub.study_hours)
35
- data["Marks"].append(sub.marks)
36
- return pd.DataFrame(data)
37
 
38
  def calculate_average(self):
39
- marks = [sub.marks for sub in self.subjects]
40
  return np.mean(marks) if marks else 0
41
 
42
  def get_max_min(self):
43
- marks = [sub.marks for sub in self.subjects]
44
  return np.max(marks), np.min(marks)
45
 
46
- def predict_performance(self, extra_hours=0):
47
- predicted_marks = []
48
- for sub in self.subjects:
49
- increase = extra_hours * 3 # simple formula
50
- predicted_marks.append(min(sub.marks + increase, 100))
51
- return np.mean(predicted_marks) if predicted_marks else 0
 
 
 
 
 
 
 
 
 
 
 
52
 
53
  def get_grade(self, marks):
54
  if marks >= 85:
@@ -59,8 +73,7 @@ class Student:
59
  return "C"
60
  elif marks >= 40:
61
  return "D"
62
- else:
63
- return "F"
64
 
65
  def best_subject(self):
66
  return max(self.subjects, key=lambda x: x.marks).name
@@ -70,96 +83,113 @@ class Student:
70
 
71
  def suggest_improvement(self):
72
  weak = self.weak_subject()
73
- return f"Focus more on {weak} and increase study hours."
74
 
75
 
76
  # -------------------------------
77
- # STREAMLIT UI
78
  # -------------------------------
 
 
79
 
80
- st.title("๐Ÿ“š Smart Study Planner")
 
 
81
 
82
- # Student Name
83
- student_name = st.text_input("Enter Student Name")
84
 
85
- # Initialize session state
86
- if "student" not in st.session_state:
87
- st.session_state.student = None
88
 
89
- if student_name:
90
- st.session_state.student = Student(student_name)
91
 
92
- # Input Fields
93
- subject_name = st.text_input("Subject Name")
94
- study_hours = st.number_input("Study Hours", min_value=0.0, step=0.5)
95
- marks = st.number_input("Marks", min_value=0, max_value=100)
96
 
97
- # Add Subject Button
98
- if st.button("Add Subject"):
99
- if subject_name and st.session_state.student:
100
- subject = Subject(subject_name, study_hours, marks)
101
- st.session_state.student.add_subject(subject)
102
- st.success(f"{subject_name} added!")
103
- else:
104
- st.error("Please enter valid data!")
105
 
106
- # Analyze Button
107
- if st.button("Analyze Performance"):
108
- student = st.session_state.student
109
 
110
- if student and student.subjects:
111
- df = student.get_data()
112
 
113
- st.subheader("๐Ÿ“Š Data Table")
114
- st.dataframe(df)
115
 
116
- avg = student.calculate_average()
117
- st.write(f"Average Marks: {avg:.2f}")
 
 
 
 
 
 
 
118
 
119
- max_marks, min_marks = student.get_max_min()
120
- st.write(f"Highest Marks: {max_marks}")
121
- st.write(f"Lowest Marks: {min_marks}")
122
 
123
- grade = student.get_grade(avg)
124
- st.write(f"Current Grade: {grade}")
125
 
126
- predicted = student.predict_performance(extra_hours=2)
127
- predicted_grade = student.get_grade(predicted)
128
 
129
- st.write(f"๐Ÿ“ˆ If you study 2 more hours, expected marks: {predicted:.2f}")
130
- st.write(f"Predicted Grade: {predicted_grade}")
 
 
131
 
132
- st.write(f"๐Ÿ† Best Subject: {student.best_subject()}")
133
- st.write(f"โš  Weak Subject: {student.weak_subject()}")
134
 
135
- st.write("๐Ÿ’ก Suggestion:", student.suggest_improvement())
 
 
 
 
136
 
137
- # Simple chart
138
- st.subheader("๐Ÿ“‰ Study Hours vs Marks")
139
- st.line_chart(df.set_index("Subject")[["Study Hours", "Marks"]])
 
140
 
141
- else:
142
- st.error("Please add subjects first!")
 
143
 
144
- # -------------------------------
145
- # KAGGLE DATASET INTEGRATION (OPTIONAL)
146
- # -------------------------------
 
 
147
 
148
- st.subheader("๐Ÿ“‚ Optional: Load Dataset")
149
 
150
- uploaded_file = st.file_uploader("Upload CSV Dataset", type=["csv"])
 
 
 
151
 
152
- if uploaded_file:
153
- df = pd.read_csv(uploaded_file)
154
 
155
- st.write("Raw Data:", df.head())
 
156
 
157
- # Cleaning
158
- df = df.drop_duplicates()
159
- df = df.fillna(df.mean(numeric_only=True))
 
160
 
161
- st.write("Cleaned Data:", df.head())
 
162
 
163
- st.write("Dataset Average:", df.mean(numeric_only=True))
164
 
165
- st.success("Dataset processed successfully!")
 
 
 
 
 
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:
20
+ def __init__(self, name, hours, marks):
21
  self.name = name
22
+ self.hours = hours
23
  self.marks = marks
24
 
25
 
 
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] # correlation
55
+ return 0
56
+
57
+ def predict_performance(self):
58
+ trend = self.performance_trend()
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
 
67
  def get_grade(self, marks):
68
  if marks >= 85:
 
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
 
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
 
139
 
140
+ if student is None or len(student.subjects) == 0:
141
+ st.error("Please add subjects first!")
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()
149
+ max_m, min_m = student.get_max_min()
150
+ grade = student.get_grade(avg)
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()}**")
187
+ st.write(f"โš  Weak Subject: **{student.weak_subject()}**")
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"))