-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptigrade_app.py
More file actions
2076 lines (1787 loc) · 98.9 KB
/
optigrade_app.py
File metadata and controls
2076 lines (1787 loc) · 98.9 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import streamlit as st
import pandas as pd
import joblib
import numpy as np
import os
import time
from dotenv import load_dotenv
import streamlit.components.v1 as components
from streamlit_extras.colored_header import colored_header
import matplotlib.pyplot as plt
import google.generativeai as genai
from sklearn.ensemble import RandomForestRegressor
import traceback
import random
# -----Logo -------------
st.set_page_config(
page_title="OptiGrade",
page_icon="https://raw.githubusercontent.com/CryptoLab-service/OptiGrade-ML-model/main/assets/Optigrade.png",
layout="wide",
initial_sidebar_state="expanded"
)
# ------------------ INITIALIZATION ------------------
# Load environment variables
load_dotenv()
api_key = os.getenv("GEMINI_API_KEY")
# ------------------ SETTING UP GOOGLE AI (GEMINI CONFIGURATION) ------------------
# Configure Gemini API
if api_key:
try:
genai.configure(api_key=api_key)
gemini_model = genai.GenerativeModel("gemini-2.5-pro")
except Exception as e:
st.error(f"Error configuring Gemini API: {str(e)}")
gemini_model = None
else:
st.error("GEMINI_API_KEY not found in environment variables")
gemini_model = None
# -------- AI Academic Recommendation -------------
def get_academic_recommendations(student_data):
"""Generate AI-powered personalized academic recommendations using Gemini"""
if not gemini_model:
return "❌ Gemini API not configured properly"
prompt = f"""
Here's the student's academic profile:
{student_data}
Generate specific, actionable academic recommendations to help this student improve their CGPA and academic performance.
Focus on:
- Study habits optimization
- Attendance improvement strategies
- Learning style adaptation
- Course difficulty management
- Time allocation suggestions
- Resource recommendations (books, online resources)
Structure your response with clear headings and bullet points. Be practical and encouraging.
"""
try:
response = gemini_model.generate_content(
prompt,
generation_config=genai.types.GenerationConfig(
temperature=0.7,
top_p=0.85,
top_k=40,
candidate_count=1
)
)
return response.text
except Exception as e:
return f"❌ Could not generate recommendations: {str(e)}"
# ------------------ SESSION STATE INITIALIZATION ------------------
if "onboarded" not in st.session_state:
st.session_state.onboarded = False
if 'page' not in st.session_state:
st.session_state.page = 'Screen 1'
if 'prev_data' not in st.session_state:
st.session_state.prev_data = []
if 'curr_data' not in st.session_state:
st.session_state.curr_data = []
if 'user_id' not in st.session_state:
st.session_state.user_id = 1
if 'user_name' not in st.session_state:
st.session_state.user_name = "Tolu John"
if 'user_pic' not in st.session_state:
st.session_state.user_pic = "👨🎓"
if 'current_cgpa' not in st.session_state:
st.session_state.current_cgpa = 3.4
if 'study_timer_active' not in st.session_state:
st.session_state.study_timer_active = False
if 'study_timer_start' not in st.session_state:
st.session_state.study_timer_start = None
if 'study_timer_duration' not in st.session_state:
st.session_state.study_timer_duration = 1500 # 25 minutes in seconds
if 'study_timer_remaining' not in st.session_state:
st.session_state.study_timer_remaining = 1500
if 'pomodoro_count' not in st.session_state:
st.session_state.pomodoro_count = 0
if 'study_goals' not in st.session_state:
st.session_state.study_goals = []
if 'resources' not in st.session_state:
st.session_state.resources = [
{"title": "Khan Academy", "url": "https://www.khanacademy.org/", "category": "General"},
{"title": "Coursera", "url": "https://www.coursera.org/", "category": "General"},
{"title": "MIT OpenCourseWare", "url": "https://ocw.mit.edu/", "category": "STEM"},
{"title": "Crash Course", "url": "https://www.youtube.com/user/crashcourse", "category": "General"},
{"title": "Wolfram Alpha", "url": "https://www.wolframalpha.com/", "category": "Math"},
{"title": "Duolingo", "url": "https://www.duolingo.com/", "category": "Languages"},
{"title": "Codecademy", "url": "https://www.codecademy.com/", "category": "Programming"},
]
# ------------------ HELPER FUNCTIONS ------------------
def grade_to_letter(grade):
"""Convert numerical grade to letter grade"""
if grade >= 70: return "A"
elif grade >= 60: return "B"
elif grade >= 50: return "C"
elif grade >= 45: return "D"
elif grade >= 40: return "E"
else: return "F"
def grade_to_color(grade):
"""Get color based on letter grade"""
if grade == "A": return "#4CAF50" # Green
elif grade == "B": return "#8BC34A" # Light Green
elif grade == "C": return "#FFEB3B" # Yellow
elif grade == "D": return "#FF9800" # Orange
elif grade == "E": return "#F44336" # Red
else: return "#B71C1C" # Dark Red (F)
def create_dotted_forecast_chart(previous_cgpa, predicted_cgpa):
"""Create sleek dotted-line CGPA forecast chart"""
fig, ax = plt.subplots(figsize=(8, 4))
x = ['Previous CGPA', 'Predicted CGPA']
y = [previous_cgpa, predicted_cgpa]
# Create dotted line with markers
ax.plot(x, y, marker='o', linestyle=':', color='#00FFD1', linewidth=2.5)
# Set chart limits and labels
ax.set_ylim(0, 5)
ax.set_title('🎯 CGPA Forecast', fontsize=14)
ax.set_ylabel('CGPA')
# Add grid with subtle styling
ax.grid(True, linestyle='--', alpha=0.3)
# Remove spines for cleaner look
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
return fig
def format_student_data():
"""
Convert current student data into a nicely formatted summary string.
"""
name = st.session_state.user_name
user_id = st.session_state.user_id
current_cgpa = st.session_state.current_cgpa
courses = st.session_state.curr_data
# Fix: Use 'course_id' instead of 'name'
course_list = "\n".join([f"{c['course_id']} ({c['course_units']} units)" for c in courses]) if courses else "No current courses."
return f"""Student Name: {name}
Student ID: {user_id}
Current CGPA: {current_cgpa}
Current Courses:
{course_list}
"""
# ------------------ DISPLAY STUDENT PROFILE ------------------
def display_student_profile():
"""Display enhanced student profile with visual elements and meaningful content"""
# Calculate values
cgpa = st.session_state.current_cgpa
courses_completed = len(st.session_state.prev_data)
current_courses = len(st.session_state.curr_data)
# ------------------ PROFILE PAGE LAYOUT ------------------
# Academic Metrics Section - Fixed 3-column layout
st.subheader("Academic Metrics")
col1, col2, col3 = st.columns(3)
# CGPA Card
with col1:
with st.container(border=True):
st.markdown("<div style='border-left: 5px solid #00FFD1; padding-left: 15px;'>", unsafe_allow_html=True)
st.markdown("**CGPA**")
st.markdown(f"<div style='font-size: 32px; font-weight: bold; color: #00FFD1;'>{cgpa:.2f}</div>",
unsafe_allow_html=True)
st.caption("Target: 3.8")
# Progress bar without help parameter
progress = min(cgpa/3.8*100, 100)
st.markdown(f"<div style='color: #AAAAAA; font-size: 12px; display: flex; justify-content: space-between;'>"
f"<span>Progress</span><span>{progress:.0f}%</span></div>",
unsafe_allow_html=True)
st.progress(int(progress))
st.markdown("</div>", unsafe_allow_html=True)
# Courses Completed Card
with col2:
with st.container(border=True):
st.markdown("<div style='border-left: 5px solid #611EE8; padding-left: 15px;'>", unsafe_allow_html=True)
st.markdown("**Courses Completed**")
st.markdown(f"<div style='font-size: 32px; font-weight: bold; color: #00FFD1;'>{courses_completed}</div>",
unsafe_allow_html=True)
st.caption("Target: 8")
# Progress bar without help parameter
progress = min(courses_completed/8*100, 100)
st.markdown(f"<div style='color: #AAAAAA; font-size: 12px; display: flex; justify-content: space-between;'>"
f"<span>Progress</span><span>{progress:.0f}%</span></div>",
unsafe_allow_html=True)
st.progress(int(progress))
st.markdown("</div>", unsafe_allow_html=True)
# Current Courses Card
with col3:
with st.container(border=True):
st.markdown("<div style='border-left: 5px solid #FF4B4B; padding-left: 15px;'>", unsafe_allow_html=True)
st.markdown("**Current Courses**")
st.markdown(f"<div style='font-size: 32px; font-weight: bold; color: #00FFD1;'>{current_courses}</div>",
unsafe_allow_html=True)
st.caption("Target: 5")
# Progress bar without help parameter
progress = min(current_courses/5*100, 100)
st.markdown(f"<div style='color: #AAAAAA; font-size: 12px; display: flex; justify-content: space-between;'>"
f"<span>Progress</span><span>{progress:.0f}%</span></div>",
unsafe_allow_html=True)
st.progress(int(progress))
st.markdown("</div>", unsafe_allow_html=True)
st.divider()
# Additional Info Section
col4, col5 = st.columns(2)
# Primary Learning Style Card
with col4:
with st.container(border=True):
st.markdown("**Primary Learning Style**")
st.markdown("<div style='font-size: 48px; text-align: center;'>🎨</div>", unsafe_allow_html=True)
st.markdown("<div style='text-align: center; font-size: 20px;'>Visual</div>", unsafe_allow_html=True)
st.caption("Prefers diagrams, charts, and visual aids")
# Academic Goals Card
with col5:
with st.container(border=True):
st.markdown("""
<div style="min-height: 180px;">
<strong>Academic Goals</strong>
<div style="display: flex; gap: 10px; margin-top: 10px; margin-bottom: 20px;">
<span style="background: #59a14f22; color: #59a14f; padding: 5px 12px; border-radius: 12px; font-size: 14px;">
CGPA 3.8+
</span>
<span style="background: #4e79a722; color: #4e79a7; padding: 5px 12px; border-radius: 12px; font-size: 14px;">
Graduate with Honors
</span>
</div>
<p style="font-size: 13px; text-align: center; color: gray;">2 active goals this semester</p>
</div>
""", unsafe_allow_html=True)
st.divider()
# Achievements Section
st.subheader("🏆 Recent Achievements")
# Achievement badges
col6, col7, col8, col9 = st.columns(4)
with col6:
with st.container(border=True, height=100):
st.markdown("<div style='text-align: center;'>🥇</div>", unsafe_allow_html=True)
st.markdown("<div style='text-align: center;'>Top 10% in problem solving</div>", unsafe_allow_html=True)
with col7:
with st.container(border=True, height=100):
st.markdown("<div style='text-align: center;'>📚</div>", unsafe_allow_html=True)
st.markdown("<div style='text-align: center;'>5 Books Read</div>", unsafe_allow_html=True)
with col8:
with st.container(border=True, height=100):
st.markdown("<div style='text-align: center;'>⏱️</div>", unsafe_allow_html=True)
st.markdown("<div style='text-align: center;'>50 Study Hours</div>", unsafe_allow_html=True)
with col9:
with st.container(border=True, height=100):
st.markdown("<div style='text-align: center;'>🏅</div>", unsafe_allow_html=True)
st.markdown("<div style='text-align: center;'>Academic Excellence</div>", unsafe_allow_html=True)
# Add subtle animations
st.markdown("""
<style>
@keyframes fadeIn {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
div[data-testid="stHorizontalBlock"] {
animation: fadeIn 0.5s ease-out;
}
div[data-testid="stHorizontalBlock"]:nth-child(1) { animation-delay: 0.1s; }
div[data-testid="stHorizontalBlock"]:nth-child(2) { animation-delay: 0.2s; }
div[data-testid="stHorizontalBlock"]:nth-child(3) { animation-delay: 0.3s; }
div[data-testid="stHorizontalBlock"]:nth-child(4) { animation-delay: 0.4s; }
</style>
""", unsafe_allow_html=True)
# ------------------ PROFILE PAGE ------------------
# Create tabs for different profile sections with meaningful content
tab1, tab2, tab3 = st.tabs(["📚 Courses", "📊 Performance", "🎯 Goals"])
# ------------------ COURSES TAB ------------------
# Courses Tab Content
with tab1:
st.subheader("Course History")
if st.session_state.prev_data or st.session_state.curr_data:
col1, col2 = st.columns(2)
with col1:
st.markdown("#### 📖 Previous Courses")
if st.session_state.prev_data:
prev_df = pd.DataFrame(st.session_state.prev_data)
# Create letter grades and colors
prev_df['Letter Grade'] = prev_df['grade'].apply(grade_to_letter)
prev_df['Grade Color'] = prev_df['Letter Grade'].apply(grade_to_color)
# Display as styled table - MATCHING CURRENT COURSES DESIGN
for _, row in prev_df.iterrows():
st.markdown(f"""
<div style="background: #1e1e2e; border-radius: 8px; padding: 12px; margin-bottom: 10px;
border-left: 4px solid {row['Grade Color']};">
<div style="display: flex; justify-content: space-between; align-items: center;">
<div>
<strong>{row['course_id']}</strong>
<div style="font-size: 13px; color: #AAAAAA; margin-top: 5px;">
Previous Course • {row['course_units']} units
</div>
</div>
<div style="font-size: 24px; font-weight: bold; color: {row['Grade Color']}">
{row['grade']}
</div>
</div>
<div style="margin-top: 10px;">
<div style="display: flex; justify-content: space-between; font-size: 12px; color: #AAAAAA;">
<span>Grade</span>
<span>{row['Letter Grade']}</span>
</div>
<div style="height: 6px; background: #2D3746; border-radius: 3px; margin-top: 5px;">
<div style="height: 100%; width: 100%; background: {row['Grade Color']}; border-radius: 3px;"></div>
</div>
</div>
</div>
""", unsafe_allow_html=True)
else:
st.info("No previous courses recorded")
with col2:
st.markdown("#### 📝 Current Courses")
if st.session_state.curr_data:
curr_df = pd.DataFrame(st.session_state.curr_data)
for _, row in curr_df.iterrows():
progress = random.randint(30, 80) # Simulated progress
st.markdown(f"""
<div style="background: #1e1e2e; border-radius: 8px; padding: 12px; margin-bottom: 10px;
border-left: 4px solid #00FFD1;">
<div style="display: flex; justify-content: space-between; align-items: center;">
<div>
<strong>{row['course_id']}</strong>
<div style="font-size: 13px; color: #AAAAAA; margin-top: 5px;">
Current Course • {row['course_units']} units
</div>
</div>
</div>
<div style="margin-top: 10px;">
<div style="display: flex; justify-content: space-between; font-size: 12px; color: #AAAAAA;">
<span>Progress</span>
<span>{progress}%</span>
</div>
<div style="height: 6px; background: #2D3746; border-radius: 3px; margin-top: 5px;">
<div style="height: 100%; width: {progress}%; background: #00FFD1; border-radius: 3px;"></div>
</div>
</div>
</div>
""", unsafe_allow_html=True)
else:
st.info("No current courses registered")
else:
st.info("No course information available")
with tab2:
st.subheader("Academic Performance")
if st.session_state.prev_data:
# Create a performance chart
perf_df = pd.DataFrame(st.session_state.prev_data)
perf_df['Letter Grade'] = perf_df['grade'].apply(grade_to_letter)
# Calculate GPA per course (simple conversion)
grade_points = {'A': 5, 'B': 4, 'C': 3, 'D': 2, 'E': 1, 'F': 0}
perf_df['Grade Points'] = perf_df['Letter Grade'].map(grade_points)
# Performance metrics
col1, col2, col3 = st.columns(3)
col1.metric("Highest Grade", f"{perf_df['grade'].max()}%")
col2.metric("Average Grade", f"{perf_df['grade'].mean():.1f}%")
col3.metric("Lowest Grade", f"{perf_df['grade'].min()}%")
# Create bar chart of grades
fig, ax = plt.subplots(figsize=(10, 4))
colors = [grade_to_color(grade) for grade in perf_df['Letter Grade']]
bars = ax.bar(perf_df['course_id'], perf_df['grade'], color=colors)
ax.set_ylim(0, 100)
ax.set_title('Course Performance', fontsize=14)
ax.set_ylabel('Grade (%)')
ax.grid(axis='y', linestyle='--', alpha=0.3)
# Add letter grades on bars
for bar, letter in zip(bars, perf_df['Letter Grade']):
height = bar.get_height()
ax.text(bar.get_x() + bar.get_width()/2., height-5,
f"{letter}", ha='center', va='top', color='white',
fontweight='bold', fontsize=10)
st.pyplot(fig)
# Attendance and study hours analysis
st.markdown("#### 📊 Study Habits Analysis")
col1, col2 = st.columns(2)
with col1:
st.markdown("##### Attendance Rate")
avg_attendance = perf_df['attendance'].mean()
fig, ax = plt.subplots(figsize=(3, 3))
ax.pie([avg_attendance, 100-avg_attendance],
colors=['#00FFD1', '#2D3746'],
startangle=90,
wedgeprops={'linewidth': 1, 'edgecolor': '#1e1e2e'})
ax.text(0, 0, f"{avg_attendance:.0f}%", ha='center', va='center',
fontsize=16, fontweight='bold', color='white')
st.pyplot(fig)
with col2:
st.markdown("##### Weekly Study Hours")
avg_study_hours = perf_df['study_hours'].mean()
fig, ax = plt.subplots(figsize=(6, 3))
ax.barh(['Average'], [avg_study_hours], color='#00FFD1')
ax.set_xlim(0, 20)
ax.set_title(f'{avg_study_hours:.1f} hours/week', fontsize=12)
ax.grid(axis='x', linestyle='--', alpha=0.3)
ax.set_facecolor('#1e1e2e')
st.pyplot(fig)
else:
st.info("No performance data available")
with tab3:
st.subheader("Academic Goals")
st.markdown("""
<div style="background: #1e1e2e; border-radius: 10px; padding: 20px; margin-bottom: 20px;">
<h4 style="margin-top: 0;">🎯 Current Goals</h4>
<ul style="padding-left: 20px;">
<li>Achieve 3.8+ CGPA this semester</li>
<li>Complete all assignments at least 2 days before deadline</li>
<li>Attend 95% of all lectures</li>
<li>Join at least one academic club</li>
</ul>
</div>
""", unsafe_allow_html=True)
st.markdown("#### 📈 Goal Progress")
# Goal tracking visualization
goals = [
{"name": "CGPA Target", "progress": 68, "target": 100},
{"name": "Assignment Completion", "progress": 85, "target": 100},
{"name": "Lecture Attendance", "progress": 92, "target": 95},
{"name": "Study Hours", "progress": 75, "target": 100}
]
for goal in goals:
st.markdown(f"""
<div style="margin-bottom: 15px;">
<div style="display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 5px;">
<span>{goal['name']}</span>
<span>{goal['progress']}% of {goal['target']}%</span>
</div>
<div style="height: 10px; background: #2D3746; border-radius: 5px;">
<div style="height: 100%; width: {min(goal['progress'], 100)}%;
background: linear-gradient(90deg, #00FFD1, #1C69B2); border-radius: 5px;"></div>
</div>
</div>
""", unsafe_allow_html=True)
st.markdown("""
<div style="background: #1e1e2e; border-radius: 10px; padding: 20px; margin-top: 20px;">
<h4 style="margin-top: 0;">🏆 Recent Achievements</h4>
<div style="display: flex; gap: 15px; margin-top: 15px;">
<div style="text-align: center;">
<div style="font-size: 24px;">🥇</div>
<div style="font-size: 12px;">Top 10% in Physics</div>
</div>
<div style="text-align: center;">
<div style="font-size: 24px;">📚</div>
<div style="font-size: 12px;">5 Books Read</div>
</div>
<div style="text-align: center;">
<div style="font-size: 24px;">⏱️</div>
<div style="font-size: 12px;">50 Study Hours</div>
</div>
</div>
</div>
""", unsafe_allow_html=True)
# ------------------ STUDY TIMER FUNCTIONS ------------------
# ------------------ STUDY TIMER ------------------
def format_time(seconds):
"""Format seconds to MM:SS"""
minutes = seconds // 60
seconds %= 60
return f"{minutes:02d}:{seconds:02d}"
def start_study_timer(duration):
"""Start the study timer"""
st.session_state.study_timer_active = True
st.session_state.study_timer_start = time.time()
st.session_state.study_timer_duration = duration
st.session_state.study_timer_remaining = duration
def stop_study_timer():
"""Stop the study timer"""
st.session_state.study_timer_active = False
st.session_state.pomodoro_count += 1
def get_achievement_badge(count):
"""Get achievement badge based on pomodoro count"""
if count < 5:
return "🌱 Beginner"
elif count < 10:
return "📚 Learner"
elif count < 20:
return "🎓 Scholar"
elif count < 30:
return "🌟 Master"
else:
return "🏆 Grand Master"
# Feedback functions
def generate_feedback(predicted_cgpa, input_features):
"""Generate brief, specific, actionable personalized feedback and study tips based on prediction"""
# Basic feedback based on predicted CGPA
if predicted_cgpa >= 3.7:
feedback = "🌟 Excellent progress! You're on track for top honours."
elif predicted_cgpa >= 3.0:
feedback = "👍 Solid performance—keep up the consistency!"
elif predicted_cgpa >= 2.5:
feedback = "🛠️ Moderate zone—consider boosting study hours and engagement."
else:
feedback = "🚧 At-risk range. Let's build a stronger study plan."
# Specific tips based on weaknesses
tips = []
# Attendance-related tips
if input_features.get("Attendance %", 0) < 70:
tips.append("📅 **Attendance Boost**: Try to attend at least 85% of classes. Regular attendance correlates with better grades.")
# Study hours tips
if input_features.get("Study Hours per Week", 0) < 15:
tips.append("⏱️ **Study Time**: Aim for 15-20 hours/week of focused study. Quality matters more than quantity!")
# Assignment completion tips
if input_features.get("Assignments Completed", 0) < 80:
tips.append("📝 **Assignments**: Complete all assignments on time. They're crucial for reinforcing concepts.")
# Midterm performance tips
if input_features.get("Midterm Score", 0) < 60:
tips.append("📚 **Midterm Prep**: Review midterm mistakes. Focus on weak areas before finals.")
# Engagement tips
if input_features.get("Lecture Engagement", 0) < 70:
tips.append("💬 **Engagement**: Actively participate in lectures. Ask questions and join discussions.")
# General tips if no specific weaknesses
if not tips:
tips.append("🎯 **Maintain Momentum**: Your current habits are working well. Keep refining your approach!")
return feedback, tips
# Animation functions
def fade_in():
return """
<style>
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
.fade-in {
animation: fadeIn 1.5s ease-in;
}
</style>
"""
def slide_in():
return """
<style>
@keyframes slideIn {
from { transform: translateX(-100px); opacity: 0; }
to { transform: translateX(0); opacity: 1; }
}
.slide-in {
animation: slideIn 1s ease-out;
}
</style>
"""
def map_features_to_model(input_features):
"""Map current feature names to what the model expects"""
feature_mapping = {
'Assignments Completed': 'credit_load',
'Attendance %': 'attendance',
'Current GPA': 'current_CGPA',
'Lecture Engagement': 'engagement',
'Midterm Score': 'midterm_score',
'Study Hours per Week': 'study_hours'
}
# Create a dictionary with model-expected features
mapped_features = {}
# Map known features
for new_name, old_name in feature_mapping.items():
if new_name in input_features:
mapped_features[old_name] = input_features[new_name]
# Add GPA_last_semester if available
if 'last_semester_gpa' in st.session_state:
mapped_features['GPA_last_semester'] = st.session_state.last_semester_gpa
else:
mapped_features['GPA_last_semester'] = st.session_state.current_cgpa
# Add default values for any missing expected features
expected_features = st.session_state.expected_features
for feature in expected_features:
if feature not in mapped_features:
# Provide default value if feature is missing
mapped_features[feature] = 0.0
return mapped_features
# ------------------ MODEL LOADING ------------------
try:
# Try loading the model as a dictionary first
model_data = joblib.load("models/model.pkl")
if isinstance(model_data, dict) and 'model' in model_data:
# New format: dictionary with model and feature names
ml_model = model_data['model']
expected_features = model_data['feature_names']
else:
# Old format: just the model object
ml_model = model_data
# Define expected features based on your training
expected_features = [
'GPA_last_semester',
'credit_load',
'current_CGPA',
'study_hours',
'attendance',
'engagement',
'midterm_score'
]
st.session_state.ml_model = ml_model
st.session_state.expected_features = expected_features
except Exception as e:
st.error(f"❌ Could not load ML model: {e}")
st.session_state.ml_model = None
st.session_state.expected_features = []
# ------------------ UI COMPONENTS ------------------
# ---------- Logo ------------------
def render_logo():
"""Render the OptiGrade logo with animation"""
components.html(fade_in() + """
<div class="fade-in" style="display: flex; justify-content: center; align-items: center; padding: 30px;">
<svg viewBox="0 0 150 150" xmlns="http://www.w3.org/2000/svg" style="width: 150px; height: auto;">
<rect width="150" height="150" rx="36.875" fill="url(#paint0_linear_826_2220)"/>
<path d="M64.8293 43.5172C57.7138 40.1199 47.7683 38.4558 34.4532 38.3967C33.1975 38.3797 31.9664 38.7458 30.9241 39.4464C30.0685 40.0247 29.3682 40.8043 28.8847 41.7168C28.4012 42.6292 28.1493 43.6465 28.1511 44.6791V101.024C28.1511 104.832 30.861 107.706 34.4532 107.706C48.4498 107.706 62.4896 109.014 70.899 116.962C71.014 117.071 71.1586 117.144 71.3148 117.172C71.471 117.2 71.6319 117.181 71.7775 117.118C71.9231 117.055 72.047 116.951 72.1338 116.818C72.2206 116.685 72.2665 116.53 72.2657 116.371V49.9807C72.2659 49.5328 72.1701 49.0901 71.9846 48.6824C71.7991 48.2747 71.5283 47.9116 71.1904 47.6175C69.2642 45.9707 67.1245 44.5915 64.8293 43.5172ZM119.909 39.4405C118.867 38.7417 117.635 38.3775 116.38 38.3967C103.065 38.4558 93.1197 40.1121 86.0043 43.5172C83.7092 44.5895 81.5689 45.966 79.6411 47.6096C79.304 47.9041 79.0337 48.2674 78.8486 48.675C78.6635 49.0826 78.5677 49.5252 78.5678 49.9729V116.367C78.5677 116.52 78.6126 116.669 78.6969 116.796C78.7812 116.923 78.9012 117.022 79.0417 117.081C79.1822 117.14 79.337 117.157 79.4868 117.128C79.6365 117.099 79.7745 117.027 79.8834 116.921C84.9388 111.899 93.811 107.7 116.388 107.702C118.06 107.702 119.663 107.038 120.844 105.856C122.026 104.674 122.69 103.071 122.69 101.4V44.6811C122.693 43.6464 122.44 42.6271 121.955 41.7131C121.47 40.7991 120.768 40.0186 119.909 39.4405Z" fill="white"/>
<defs>
<linearGradient id="paint0_linear_826_2220" x1="-13.75" y1="101.25" x2="149.672" y2="34.2008" gradientUnits="userSpaceOnUse">
<stop stop-color="#1C69B2"/>
<stop offset="0.677451" stop-color="#611EE8"/>
</linearGradient>
</defs>
</svg>
</div>
""", height=240)
# ------------------ MAIN APP LAYOUT ------------------
render_logo()
# ------------------ ONBOARDING ------------------
if not st.session_state.onboarded:
components.html(slide_in() + """
<div class="slide-in">
<h1 style='text-align: center; font-size: 64px; color: white;'>Welcome to OptiGrade Demo Engine!</h1>
<p style='text-align: center; color: white; font-size: 18px;'>Smart academic insights to help you study better and succeed with confidence.</p>
</div>
""", height=150)
st.markdown("<div style='height: 40px;'></div>", unsafe_allow_html=True)
col1, col2, col3 = st.columns([3, 4, 3])
with col2:
if st.button("Lets get you Started!", key="view_mobile_button", use_container_width=True):
st.session_state.onboarded = True
st.rerun()
# ------------------ DASHBOARD ------------------
if st.session_state.onboarded:
# Sidebar with user profile
with st.sidebar:
# User profile
st.markdown(f"""
<div style="text-align: center; padding: 20px 0;">
<div style="font-size: 48px; margin-bottom: 10px;">{st.session_state.user_pic}</div>
<h3 style="margin: 0;">{st.session_state.user_name}</h3>
<p style="color: #888; margin-top: 5px;">Student ID: {st.session_state.user_id}</p>
<p style="color: #888; margin-top: 5px;">CGPA: {st.session_state.current_cgpa:.2f}</p>
</div>
""", unsafe_allow_html=True)
st.divider()
# Notifications
st.markdown("### 🔔 Notifications")
st.info("New semester start next week!")
st.info("Assignment due: Calculus - May 15")
# Social Media Links
st.divider()
st.markdown("### 🌐 Connect With Me")
st.markdown("""
<div style="margin-top: 20px;">
<a href="https://linkedin.com/in/oluwalowojohn" target="_blank" style="text-decoration: none; color: white; display: block; margin: 10px 0; padding: 8px; border-radius: 8px; background: #1e1e2e;">
<img src="https://cdn-icons-png.flaticon.com/512/174/174857.png" width="24" style="vertical-align: middle; margin-right: 10px;"> LinkedIn
</a>
<a href="https://x.com/encryptedMFI" target="_blank" style="text-decoration: none; color: white; display: block; margin: 10px 0; padding: 8px; border-radius: 8px; background: #1e1e2e;">
<img src="https://cdn-icons-png.flaticon.com/512/124/124021.png" width="24" style="vertical-align: middle; margin-right: 10px;"> X (Twitter)
</a>
<a href="https://facebook.com/oluwalowojohn" target="_blank" style="text-decoration: none; color: white; display: block; margin: 10px 0; padding: 8px; border-radius: 8px; background: #1e1e2e;">
<img src="https://cdn-icons-png.flaticon.com/512/124/124010.png" width="24" style="vertical-align: middle; margin-right: 10px;"> Facebook
</a>
<a href="https://wa.me/+2347030739128" target="_blank" style="text-decoration: none; color: white; display: block; margin: 10px 0; padding: 8px; border-radius: 8px; background: #1e1e2e;">
<img src="https://cdn-icons-png.flaticon.com/512/124/124034.png" width="24" style="vertical-align: middle; margin-right: 10px;"> WhatsApp
</a>
<a href="mailto:oluwalowojohn@gmail.com" style="text-decoration: none; color: white; display: block; margin: 10px 0; padding: 8px; border-radius: 8px; background: #1e1e2e;">
<img src="https://cdn-icons-png.flaticon.com/512/561/561127.png" width="24" style="vertical-align: middle; margin-right: 10px;"> Email
</a>
<a href="https://zoetechhub.name.ng" target="_blank" style="text-decoration: none; color: white; display: block; margin: 10px 0; padding: 8px; border-radius: 8px; background: #1e1e2e;">
<img src="https://cdn-icons-png.flaticon.com/512/1006/1006771.png" width="24" style="vertical-align: middle; margin-right: 10px;"> Website
</a>
</div>
""", unsafe_allow_html=True)
st.divider()
# Newsletter Signup
st.markdown("### ✉️ Stay Updated")
email = st.text_input("Your Email", placeholder="connect@optigrade.app")
if st.button("Subscribe to Newsletter"):
st.success("Thanks for subscribing! You'll receive our updates.")
st.divider()
# App Info
st.markdown("### ℹ️ About OptiGrade")
st.markdown("""
<div style="font-size: 14px; color: #888;">
Version: 2.0.0<br>
Last Updated: July 26, 2025<br>
License: MIT<br>
© 2025 OptiGrade
</div>
""", unsafe_allow_html=True)
# Create tabs at the top level
tabs = st.tabs([
"ℹ️ About",
"🚀 Features",
"🧠 CGPA Predictor",
"📘 Study Hub",
"📂 Course Manager",
"📚 Resources",
"👤 User Profile"
])
#--------------------------ABOUT TAB ---------------------------
with tabs[0]: # ℹ️ About Tab
# Hero Section without box
st.markdown("""
<div style="text-align: center; margin-bottom: 40px;">
<h1 style="color: #ffff; margin-bottom: 10px;">👋 Welcome to OptiGrade Engine!</h1>
<p style="font-size: 18px; max-width: 800px; margin: 0 auto;">
Explore the prototype behind OptiGrade's intelligent academic ecosystem — where machine learning meets personalized study planning. This demo showcases how our predictive models, adaptive feedback systems, and academic forecasting workflows function beneath the hood.</p>
</div>
""", unsafe_allow_html=True)
# Prototype in expander - collapsed by default
# 🎨 Frosted Glass Container with Figma SVG and Bold Text
figma_svg = """
<svg width="20" height="20" viewBox="0 0 128 128" fill="none" xmlns="http://www.w3.org/2000/svg">
<circle cx="64" cy="64" r="64" fill="#1E1E1E"/>
<g transform="translate(32,32)">
<path d="M32 0C40.8366 0 48 7.16344 48 16C48 24.8366 40.8366 32 32 32H16V16C16 7.16344 23.1634 0 32 0Z" fill="#0ACF83"/>
<path d="M16 32H0V16C0 7.16344 7.16344 0 16 0H32V32H16Z" fill="#A259FF"/>
<path d="M0 32H16V64H0V32Z" fill="#F24E1E"/>
<path d="M16 32H32C40.8366 32 48 39.1634 48 48C48 56.8366 40.8366 64 32 64C23.1634 64 16 56.8366 16 48V32Z" fill="#FF7262"/>
<path d="M32 64C40.8366 64 48 56.8366 48 48C48 39.1634 40.8366 32 32 32C23.1634 32 16 39.1634 16 48C16 56.8366 23.1634 64 32 64Z" fill="#1ABCFE"/>
</g>
</svg>
"""
# 🧊 Frosted Glass Styling
st.markdown("""
<div style="
backdrop-filter: blur(12px);
background-color: rgba(255, 255, 255, 0.05);
border-radius: 14px;
padding: 20px;
box-shadow: 0 4px 18px rgba(0,0,0,0.25);
border: 1px solid rgba(255,255,255,0.08);
</div>
""", unsafe_allow_html=True)
with st.expander("**📱 View Mobile Prototype**", expanded=False):
components.html("""
<iframe style="border: none; border-radius: 12px; box-shadow: 0 4px 12px rgba(0,0,0,0.15);"
width="100%" height="420"
src="https://www.figma.com/embed?embed_host=streamlit&url=https://www.figma.com/proto/B2L8DOx0u3xuSWPhKpJpO5/OptiGrade-Mobile-App---EduTech?node-id=802-966&starting-point-node-id=802%3A966&scaling=scale-down"
allowfullscreen></iframe>
""", height=420)
# Problem/Solution section
col1, col2 = st.columns(2)
with col1:
st.markdown("### 😓 Challenges Faced")
st.markdown("""
Higher institution students struggle with:
- **Inefficient study habits** - Wasting time on ineffective methods
- **Lack of personalized guidance** - One-size-fits-all academic advice
- **Performance uncertainty** - Difficulty predicting academic outcomes
- **Overwhelming course loads** - Managing multiple deadlines and priorities
- **Mental health challenges** - Managing stress, anxiety and burnouts
""")
with col2:
st.markdown("### 💡 Our Solution")
st.markdown("""
OptiGrade aims to provide:
- **AI-powered CGPA forecasting** with 92% forcasting accuracy
- **Personalized study plans** tailored to your learning style
- **Smart study tools** including Pomodoro timer and goal tracking
- **Performance analytics** to identify strengths and weaknesses
- **Resource recommendations** curated for your courses
""")
# Innovation Section
st.markdown("### ✨ Why OptiGrade is Revolutionary")
st.markdown("""
OptiGrade transforms academic planning through:
- **Closed-Loop Intelligence**: Forecasts shape study plans → completed tasks refine predictions
- **Behavioural Adaptation**: Learns your unique study patterns and preferences
- **Predictive Accuracy**: Machine learning models trained on academic patterns
- **Holistic Ecosystem**: Combines forecasting, planning, and resource management
""")
# How It Works Diagram
st.markdown("### 🔄 The OptiGrade Feedback Loop")
st.image("assets/feedback_loop.png",
use_container_width=True)
# Core Technology Section
st.markdown("### ⚙️ Technical Foundation")
col1, col2, col3 = st.columns(3)
with col1:
st.markdown("""
<div style="background: #1e1e2e; border-radius: 10px; padding: 20px; height: 200px;">
<h4>🔮 Predictive Engine</h4>
<p>ML models trained on academic histories and behavioural patterns</p>
</div>
""", unsafe_allow_html=True)
with col2:
st.markdown("""
<div style="background: #1e1e2e; border-radius: 10px; padding: 20px; height: 200px;">
<h4>🧠 Adaptive AI</h4>
<p>AI-powered recommendations that evolve with your learning journey</p>
</div>
""", unsafe_allow_html=True)
with col3:
st.markdown("""
<div style="background: #1e1e2e; border-radius: 10px; padding: 20px; height: 200px;">
<h4>📱 Cross-Platform</h4>
<p>Mobile-first design with future web application capabilities</p>
</div>
""", unsafe_allow_html=True)
# Feature Showcase
st.markdown("### 🚀 Core Capabilities")
features = [
("📊", "CGPA Forecasting", "92% accurate predictions using Machine Learning (ML) models"),
("🎯", "Personalized Study Plans", "AI-generated recommendations based on your patterns"),
("⏱️", "Smart Study Tools", "Pomodoro timer, goal tracking, and progress analytics"),
("📚", "Resource Integration", "Curated academic content tailored to your courses"),
("🔔", "Proactive Alerts", "Notifications for at-risk courses and deadlines"),
("📈", "Performance Analytics", "Visual insights into strengths and weaknesses")
]
for i in range(0, len(features), 2):
cols = st.columns(2)
for j in range(2):
if i+j < len(features):
with cols[j]:
icon, title, desc = features[i+j]
st.markdown(f"""
<div style="background: #1e1e2e;
border-radius: 10px;
padding: 20px;
margin-bottom: 20px;
border-left: 4px solid #00FFD1;">
<div style="font-size: 24px; margin-bottom: 10px;">{icon} {title}</div>
<p style="color: #AAAAAA; margin: 0;">{desc}</p>
</div>
""", unsafe_allow_html=True)
# Technical Diagram Explanation
with st.expander("🔍 See how the App Design System Works"):
st.markdown("""
**OptiGrade's technical architecture:**
1. **Data Ingestion**: Academic history, study patterns, and course details
2. **Machine Learning Engine**: Processes data to generate predictions
3. **Recommendation System**: Creates personalized study plans
4. **User Interaction**: Students implement recommendations
5. **Feedback Loop**: Completed tasks refine future predictions
```mermaid
graph LR
A [Academic History] ----> B (ML Engine)
C [Study Patterns] ----> B (ML Engine)
D [Course Details] ----> B (ML Engine)
B [ML Engine] ----> E (Predictions)
E [Predictions] ----> F (Recommendations)
F [Recommendations] ----> G (User Actions)
G [User Actions] ----> B (ML Engine)
```
""")
# Roadmap and Vision
st.markdown("### 🛣️ Our Development Roadmap")
roadmap_col1, roadmap_col2 = st.columns(2)
with roadmap_col1:
st.markdown("""
**2024 - Phase 1**
- UI Screens designs
- CGPA Prediction Engine
- Study Planner & Goal Tracker
- Performance Dashboard
- Resource Libraries
""")
with roadmap_col2:
st.markdown("""
**2025 - Phase 2**
- Collaborative Learning Forums
- Gamified Progress Rewards
- Institutional Integration
- NLP Feedback Analysis
- Offline Capabilities
""")