mjkalas's picture
Upload 2 files
7eeb69d verified
Raw History Blame Contribute Delete
20.5 kB
import streamlit as st
import json
import os
st.set_page_config(
page_title="Ole Miss Degree Planner",
page_icon="πŸŽ“",
layout="wide",
initial_sidebar_state="collapsed",
)
st.markdown("""
<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
html, body, [class*="css"] {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.stApp { background: #f0f0f5; }
#MainMenu, footer, header { visibility: hidden; }
.block-container { padding: 2rem 2rem 4rem 2rem; max-width: 1100px; }
.hero {
background: linear-gradient(135deg, #1d1d1f 0%, #3a3a3c 100%);
border-radius: 20px;
padding: 2rem 2.5rem;
margin-bottom: 1.5rem;
box-shadow: 0 4px 24px rgba(0,0,0,0.22);
display: flex;
align-items: center;
gap: 1.6rem;
}
.hero-text h1 { font-size: 2.2rem; font-weight: 700; letter-spacing: -0.5px; margin: 0 0 0.25rem 0; color: #f5f5f7; }
.hero-text p { font-size: 1rem; color: #aeaeb2; margin: 0; }
/* Tab strip */
div[data-testid="stTabs"] button {
font-weight: 600 !important;
border-radius: 10px 10px 0 0 !important;
}
div[data-testid="stTabs"] button[aria-selected="true"] {
color: #CE2128 !important;
border-bottom: 2px solid #CE2128 !important;
}
.card { background: #ffffff; border-radius: 16px; padding: 1.6rem 1.8rem; box-shadow: 0 2px 12px rgba(0,0,0,0.09); margin-bottom: 1.2rem; }
.card-header { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; color: #CE2128; margin-bottom: 0.8rem; }
.stat-row { display: flex; gap: 0.8rem; flex-wrap: wrap; margin: 1rem 0 0.3rem; }
.stat-chip { background: #1d1d1f; border-radius: 14px; padding: 0.75rem 1rem; text-align: center; flex: 1; min-width: 80px; }
.stat-chip .val { font-size: 1.9rem; font-weight: 700; color: #ffffff; line-height: 1; }
.stat-chip .lbl { font-size: 0.68rem; color: #aeaeb2; margin-top: 0.25rem; text-transform: uppercase; letter-spacing: 0.05em; }
.pill-grid { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.6rem; }
.pill { border-radius: 20px; padding: 0.35rem 0.9rem; font-size: 0.82rem; font-weight: 600; white-space: nowrap; }
.pill-done { background: #1a5c1a; color: #e6fae6; }
.pill-remaining { background: #CE2128; color: #ffffff; }
.gpa-display { font-size: 4rem; font-weight: 700; color: #1d1d1f; letter-spacing: -2px; line-height: 1; text-align: center; }
.gpa-sub { font-size: 0.8rem; color: #6e6e73; text-align: center; margin-top: 0.3rem; }
.gpa-bar-bg { background: #e5e5ea; border-radius: 8px; height: 10px; width: 100%; margin: 1rem 0 0.5rem; }
.gpa-bar-fill { height: 10px; border-radius: 8px; transition: width 0.4s ease; }
.prog-bar-bg { background: #d1d1d6; border-radius: 8px; height: 10px; width: 100%; margin: 0.5rem 0 0.3rem; }
.prog-bar-fill { height: 10px; border-radius: 8px; background: linear-gradient(90deg, #CE2128, #ff6b6e); }
.prog-label { font-size: 0.8rem; color: #3a3a3c; font-weight: 500; display: flex; justify-content: space-between; }
.stMultiSelect span[data-baseweb="tag"] { background: #CE2128 !important; color: white !important; border-radius: 8px !important; }
.stSelectbox > div > div { border-radius: 12px !important; border-color: #c7c7cc !important; }
.stMultiSelect > div > div { border-radius: 12px !important; border-color: #c7c7cc !important; }
/* RMP card */
.rmp-card {
background: #ffffff;
border-radius: 16px;
padding: 1.8rem;
box-shadow: 0 2px 12px rgba(0,0,0,0.09);
margin-top: 1rem;
}
.rmp-name { font-size: 1.5rem; font-weight: 700; color: #1d1d1f; margin: 0 0 0.15rem; }
.rmp-dept { font-size: 0.9rem; color: #6e6e73; margin: 0 0 1.2rem; }
.rmp-stats { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.rmp-stat { background: #f0f0f5; border-radius: 12px; padding: 0.8rem 1.2rem; text-align: center; flex: 1; min-width: 90px; }
.rmp-stat .rval { font-size: 2rem; font-weight: 700; color: #1d1d1f; line-height: 1; }
.rmp-stat .rlbl { font-size: 0.7rem; color: #6e6e73; margin-top: 0.2rem; text-transform: uppercase; letter-spacing: 0.05em; }
.rmp-tag { display: inline-block; background: #1d1d1f; color: #f5f5f7; border-radius: 20px; padding: 0.25rem 0.7rem; font-size: 0.75rem; font-weight: 600; margin: 0.2rem 0.2rem 0.2rem 0; }
.rmp-link { display: inline-block; margin-top: 1rem; background: #CE2128; color: white; text-decoration: none; padding: 0.5rem 1.4rem; border-radius: 10px; font-size: 0.88rem; font-weight: 600; }
.rmp-link:hover { background: #a51a1f; }
.empty-state { background: #ffffff; border-radius: 16px; padding: 3rem 2rem; text-align: center; box-shadow: 0 2px 12px rgba(0,0,0,0.09); }
.empty-state .icon { font-size: 3.5rem; margin-bottom: 1rem; }
.empty-state .title { font-size: 1.15rem; font-weight: 600; color: #1d1d1f; margin-bottom: 0.4rem; }
.empty-state .sub { font-size: 0.9rem; color: #6e6e73; }
.footer { text-align: center; color: #8e8e93; font-size: 0.75rem; margin-top: 2rem; line-height: 1.6; }
</style>
""", unsafe_allow_html=True)
# ── Data ──────────────────────────────────────────────────────────────────────
@st.cache_data
def load_majors():
data_path = os.path.join(os.path.dirname(__file__), "majors_data.json")
with open(data_path) as f:
return json.load(f)
majors_data = load_majors()
sorted_majors = sorted(majors_data.keys())
GRADE_POINTS = {
"A": 4.0, "A-": 3.7, "B+": 3.3, "B": 3.0, "B-": 2.7,
"C+": 2.3, "C": 2.0, "C-": 1.7, "D+": 1.3, "D": 1.0, "D-": 0.7, "F": 0.0,
}
GRADE_OPTIONS = ["β€”", "A", "A-", "B+", "B", "B-", "C+", "C", "C-", "D+", "D", "D-", "F"]
OLE_MISS_RMP_ID = 1265
if "grades" not in st.session_state:
st.session_state.grades = {}
# ── RMP lookup (cached so same name isn't fetched twice per session) ──────────
@st.cache_data(show_spinner=False)
def lookup_professor(name: str):
"""Returns a dict with professor data or an error string."""
try:
import ratemyprofessor
school = ratemyprofessor.get_school_by_name("University of Mississippi")
if school is None:
return {"error": "Could not connect to Rate My Professor. Try again later."}
prof = ratemyprofessor.get_professor_by_school_and_name(school, name)
if prof is None:
return {"error": f"No professor named \"{name}\" found at Ole Miss on Rate My Professor."}
data = {
"name": prof.name,
"department": prof.department,
"rating": prof.rating,
"difficulty": prof.difficulty,
"num_ratings": prof.num_ratings,
"would_take_again": round(prof.would_take_again, 1) if prof.would_take_again is not None else None,
"url": f"https://www.ratemyprofessors.com/professor/{prof.id}",
}
return data
except ImportError:
return {"error": "The ratemyprofessor library is not installed. Make sure requirements.txt includes RateMyProfessorAPI."}
except Exception as e:
return {"error": f"Something went wrong: {str(e)}"}
# ── Hero ──────────────────────────────────────────────────────────────────────
st.markdown("""
<div class="hero">
<div>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/Ole_Miss_Rebels_wordmark.svg/320px-Ole_Miss_Rebels_wordmark.svg.png"
style="height:60px;width:auto;display:block;filter:brightness(0) invert(1);"
alt="Ole Miss" />
</div>
<div class="hero-text">
<h1>Degree Planner</h1>
<p>Plan your degree, track your GPA, and look up professor ratings β€” all in one place.</p>
</div>
</div>
""", unsafe_allow_html=True)
# ── Tabs ──────────────────────────────────────────────────────────────────────
tab_planner, tab_rmp = st.tabs(["πŸ“‹ Degree Planner", "⭐ Rate My Professor"])
# ══════════════════════════════════════════════════════════════════════════════
# TAB 1 β€” Degree Planner
# ══════════════════════════════════════════════════════════════════════════════
with tab_planner:
left, right = st.columns([1.1, 1], gap="large")
with left:
st.markdown('<div class="card">', unsafe_allow_html=True)
st.markdown('<div class="card-header">Step 1 β€” Choose Your Major</div>', unsafe_allow_html=True)
selected_major = st.selectbox("Major", options=["β€” Select a major β€”"] + sorted_majors, label_visibility="collapsed")
st.markdown('</div>', unsafe_allow_html=True)
if selected_major and selected_major != "β€” Select a major β€”":
all_courses = majors_data[selected_major]
st.markdown('<div class="card">', unsafe_allow_html=True)
st.markdown('<div class="card-header">Step 2 β€” Mark Completed Courses</div>', unsafe_allow_html=True)
st.caption("Select every course from this major's requirements that you have already passed.")
completed = st.multiselect(
"Completed courses", options=all_courses,
default=[c for c in st.session_state.grades.keys() if c in all_courses],
label_visibility="collapsed", key=f"completed_{selected_major}",
)
for k in [k for k in st.session_state.grades if k not in completed]:
del st.session_state.grades[k]
st.markdown('</div>', unsafe_allow_html=True)
if completed:
st.markdown('<div class="card">', unsafe_allow_html=True)
st.markdown('<div class="card-header">Step 3 β€” Enter Your Grades</div>', unsafe_allow_html=True)
st.caption("Select a letter grade for each completed course to calculate your GPA.")
h1, h2 = st.columns([3, 1])
h1.markdown("**Course**")
h2.markdown("**Grade**")
for course in sorted(completed):
c1, c2 = st.columns([3, 1])
c1.markdown(f"<span style='font-size:0.88rem;font-weight:500;color:#1d1d1f'>{course}</span>", unsafe_allow_html=True)
current = st.session_state.grades.get(course, "β€”")
new_grade = c2.selectbox(f"g_{course}", options=GRADE_OPTIONS,
index=GRADE_OPTIONS.index(current) if current in GRADE_OPTIONS else 0,
label_visibility="collapsed", key=f"gs_{course}")
st.session_state.grades[course] = new_grade
st.markdown('</div>', unsafe_allow_html=True)
remaining = [c for c in all_courses if c not in completed]
total = len(all_courses)
done = len(completed)
pct = int(done / total * 100) if total else 0
graded = [(c, g) for c, g in st.session_state.grades.items() if g in GRADE_POINTS and c in completed]
gpa = sum(GRADE_POINTS[g] for _, g in graded) / len(graded) if graded else None
gpa_display = f"{gpa:.2f}" if gpa is not None else "β€”"
st.markdown('<div class="card">', unsafe_allow_html=True)
st.markdown('<div class="card-header">Your Progress</div>', unsafe_allow_html=True)
st.markdown(f"""
<div class="prog-label"><span>{done} of {total} courses completed</span><span style="color:#CE2128;font-weight:700">{pct}%</span></div>
<div class="prog-bar-bg"><div class="prog-bar-fill" style="width:{pct}%"></div></div>
<div class="stat-row">
<div class="stat-chip"><div class="val">{done}</div><div class="lbl">Done</div></div>
<div class="stat-chip"><div class="val">{len(remaining)}</div><div class="lbl">Left</div></div>
<div class="stat-chip"><div class="val">{total}</div><div class="lbl">Total</div></div>
<div class="stat-chip"><div class="val">{gpa_display}</div><div class="lbl">GPA</div></div>
</div>
""", unsafe_allow_html=True)
st.markdown('</div>', unsafe_allow_html=True)
with right:
if selected_major and selected_major != "β€” Select a major β€”":
all_courses = majors_data[selected_major]
completed_list = st.session_state.get(f"completed_{selected_major}", []) or []
remaining = [c for c in all_courses if c not in completed_list]
graded = [(c, g) for c, g in st.session_state.grades.items() if g in GRADE_POINTS and c in completed_list]
gpa = sum(GRADE_POINTS[g] for _, g in graded) / len(graded) if graded else None
# GPA card
st.markdown('<div class="card">', unsafe_allow_html=True)
st.markdown('<div class="card-header">GPA Calculator</div>', unsafe_allow_html=True)
gpa_val = f"{gpa:.2f}" if gpa is not None else "β€”"
gpa_w = int(gpa / 4.0 * 100) if gpa is not None else 0
if gpa is None: bar_color = "#d1d1d6"
elif gpa >= 3.5: bar_color = "#34c759"
elif gpa >= 3.0: bar_color = "#007aff"
elif gpa >= 2.0: bar_color = "#ff9f0a"
else: bar_color = "#CE2128"
gpa_sub = f"out of 4.0 &nbsp;Β·&nbsp; {len(graded)} graded course(s)" if gpa is not None else "Enter grades in Step 3 to calculate your GPA"
st.markdown(f"""
<div class="gpa-display">{gpa_val}</div>
<div class="gpa-sub">{gpa_sub}</div>
<div class="gpa-bar-bg"><div class="gpa-bar-fill" style="width:{gpa_w}%;background:{bar_color};"></div></div>
""", unsafe_allow_html=True)
if gpa is not None:
if gpa >= 3.5: st.success("πŸŽ“ Dean's List range β€” excellent work!")
elif gpa >= 3.0: st.info("πŸ“˜ Good standing β€” keep it up!")
elif gpa >= 2.0: st.warning("⚠️ Above minimum β€” aim higher for more opportunities.")
else: st.error("🚨 Below 2.0 β€” academic probation risk. Seek advising soon.")
st.markdown('</div>', unsafe_allow_html=True)
# Remaining courses
st.markdown('<div class="card">', unsafe_allow_html=True)
st.markdown('<div class="card-header">Courses Still Needed</div>', unsafe_allow_html=True)
if not remaining:
st.success("πŸŽ‰ You've completed all listed courses for this major!")
else:
st.caption(f"{len(remaining)} course(s) remaining to finish your degree requirements.")
pills = "".join(f'<span class="pill pill-remaining">{c}</span>' for c in sorted(remaining))
st.markdown(f'<div class="pill-grid">{pills}</div>', unsafe_allow_html=True)
st.markdown('</div>', unsafe_allow_html=True)
if completed_list:
st.markdown('<div class="card">', unsafe_allow_html=True)
st.markdown('<div class="card-header">Completed Courses</div>', unsafe_allow_html=True)
pills = "".join(f'<span class="pill pill-done">{c}</span>' for c in sorted(completed_list))
st.markdown(f'<div class="pill-grid">{pills}</div>', unsafe_allow_html=True)
st.markdown('</div>', unsafe_allow_html=True)
else:
st.markdown("""
<div class="empty-state">
<div class="icon">πŸŽ“</div>
<div class="title">Select a major to get started</div>
<div class="sub">Your remaining courses, progress, and GPA will appear here.</div>
</div>
""", unsafe_allow_html=True)
# ══════════════════════════════════════════════════════════════════════════════
# TAB 2 β€” Rate My Professor
# ══════════════════════════════════════════════════════════════════════════════
with tab_rmp:
st.markdown('<div class="card">', unsafe_allow_html=True)
st.markdown('<div class="card-header">Search Ole Miss Professors</div>', unsafe_allow_html=True)
st.caption("Type a professor's last name (or full name) and hit Search to pull their Rate My Professor data.")
col_input, col_btn = st.columns([3, 1])
prof_name = col_input.text_input("Professor name", placeholder="e.g. Smith or John Smith", label_visibility="collapsed")
search_clicked = col_btn.button("Search", use_container_width=True)
st.markdown('</div>', unsafe_allow_html=True)
if search_clicked and prof_name.strip():
with st.spinner("Looking up professor on Rate My Professor…"):
result = lookup_professor(prof_name.strip())
if "error" in result:
st.error(result["error"])
else:
# Color coding for rating
r = result["rating"]
if r >= 4.0:
rating_color = "#34c759"
elif r >= 3.0:
rating_color = "#007aff"
elif r >= 2.0:
rating_color = "#ff9f0a"
else:
rating_color = "#CE2128"
# Difficulty β€” lower is better
d = result["difficulty"]
if d <= 2.5:
diff_color = "#34c759"
elif d <= 3.5:
diff_color = "#ff9f0a"
else:
diff_color = "#CE2128"
wta = result["would_take_again"]
wta_display = f"{wta}%" if wta is not None else "N/A"
st.markdown(f"""
<div class="rmp-card">
<div class="rmp-name">{result['name']}</div>
<div class="rmp-dept">{result['department']} Β· University of Mississippi Β· {result['num_ratings']} rating(s)</div>
<div class="rmp-stats">
<div class="rmp-stat">
<div class="rval" style="color:{rating_color}">{result['rating']}</div>
<div class="rlbl">Overall / 5.0</div>
</div>
<div class="rmp-stat">
<div class="rval" style="color:{diff_color}">{result['difficulty']}</div>
<div class="rlbl">Difficulty / 5.0</div>
</div>
<div class="rmp-stat">
<div class="rval">{wta_display}</div>
<div class="rlbl">Would Retake</div>
</div>
</div>
<a class="rmp-link" href="{result['url']}" target="_blank">View Full Profile on RMP β†—</a>
</div>
""", unsafe_allow_html=True)
elif search_clicked and not prof_name.strip():
st.warning("Please enter a professor's name before searching.")
else:
st.markdown("""
<div class="empty-state" style="margin-top:0.5rem;">
<div class="icon">⭐</div>
<div class="title">Look up any Ole Miss professor</div>
<div class="sub">Ratings, difficulty, and would-take-again percentage pulled live from Rate My Professor.</div>
</div>
""", unsafe_allow_html=True)
# ── Footer ────────────────────────────────────────────────────────────────────
st.markdown("""
<div class="footer">
University of Mississippi Β· Degree Planner Β· 2025–2026 Academic Year<br>
Professor data sourced from Rate My Professor. Course data from official Ole Miss program sheets.
Always verify requirements with your academic advisor.
</div>
""", unsafe_allow_html=True)