Download streamlit_app.py from sp103107/NERA: direct link, hf CLI and curl.
- Browser
- Download file 10.4 kB
-
https://huggingface.co/sp103107/NERA/resolve/main/streamlit_app.py
- Command line
-
hf download hf://sp103107/NERA/streamlit_app.py
-
curl -L -o streamlit_app.py https://huggingface.co/sp103107/NERA/resolve/main/streamlit_app.py
10.4 kB
| """ | |
| streamlit_app.py | |
| ---------------- | |
| Streamlit-based web UI for the NORA Admissions Agent demo. | |
| Responsibilities: | |
| - Load sample applications | |
| - Allow the user to run the AdmissionsAgent through a web interface | |
| - Display reviewed applications, scores, and a leaderboard | |
| - Provide detailed applicant information and explanations | |
| """ | |
| import json | |
| import streamlit as st | |
| from agent.admissions_agent import AdmissionsAgent | |
| import time | |
| def load_applications(file_path: str) -> list: | |
| """ | |
| Load applications from a JSON file. | |
| Parameters | |
| ---------- | |
| file_path : str | |
| Path to the JSON file containing applications. | |
| Returns | |
| ------- | |
| list | |
| A list of application dictionaries. | |
| """ | |
| with open(file_path, "r") as f: | |
| return json.load(f) | |
| def display_applicant_card(applicant: dict, review: dict, rank: int = None): | |
| """ | |
| Display a detailed applicant card with review information. | |
| Parameters | |
| ---------- | |
| applicant : dict | |
| Original applicant data | |
| review : dict | |
| Review results from the agent | |
| rank : int, optional | |
| Ranking position | |
| """ | |
| with st.container(): | |
| col1, col2 = st.columns([1, 2]) | |
| with col1: | |
| if rank: | |
| st.markdown(f"### π #{rank}") | |
| st.markdown(f"**{applicant['name']}**") | |
| st.markdown(f"**GPA:** {applicant.get('gpa', 'N/A')}") | |
| st.markdown(f"**SAT:** {applicant.get('sat', 'N/A')}") | |
| with col2: | |
| if 'scores' in review: | |
| scores = review['scores'] | |
| col_a, col_b, col_c, col_d = st.columns(4) | |
| with col_a: | |
| st.metric("Academics", f"{scores.get('academics', {}).get('score', 'N/A')}/10") | |
| with col_b: | |
| st.metric("Activities", f"{scores.get('activities', {}).get('score', 'N/A')}/10") | |
| with col_c: | |
| st.metric("Essay", f"{scores.get('essay', {}).get('score', 'N/A')}/10") | |
| with col_d: | |
| st.metric("Recommendations", f"{scores.get('recommendations', {}).get('score', 'N/A')}/10") | |
| if 'total_score' in review: | |
| st.markdown(f"**π― Total Score: {review['total_score']}/10**") | |
| if 'summary' in review: | |
| with st.expander("π AI Analysis"): | |
| st.write(review['summary']) | |
| st.divider() | |
| # ===================== | |
| # Streamlit UI Layout | |
| # ===================== | |
| st.set_page_config( | |
| page_title="NORA Admissions Agent", | |
| page_icon="π", | |
| layout="wide", | |
| initial_sidebar_state="expanded" | |
| ) | |
| # Custom CSS for better styling | |
| st.markdown(""" | |
| <style> | |
| .main-header { | |
| background: linear-gradient(90deg, #1f77b4, #ff7f0e); | |
| padding: 1rem; | |
| border-radius: 10px; | |
| color: white; | |
| text-align: center; | |
| margin-bottom: 2rem; | |
| } | |
| .metric-card { | |
| background-color: #f0f2f6; | |
| padding: 1rem; | |
| border-radius: 10px; | |
| border-left: 4px solid #1f77b4; | |
| } | |
| .success-message { | |
| background-color: #d4edda; | |
| color: #155724; | |
| padding: 1rem; | |
| border-radius: 10px; | |
| border: 1px solid #c3e6cb; | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| # Header | |
| st.markdown('<div class="main-header"><h1>π NORA β Northeastern Admissions Agent</h1></div>', unsafe_allow_html=True) | |
| st.markdown(""" | |
| <div style="text-align: center; margin-bottom: 2rem;"> | |
| <h3>AI-Powered Admissions Assistant</h3> | |
| <p>NORA evaluates student applications using advanced AI analysis across multiple criteria including academics, activities, essays, and recommendations.</p> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| # Sidebar | |
| st.sidebar.markdown("## ποΈ Demo Controls") | |
| st.sidebar.markdown("---") | |
| # Demo options | |
| demo_mode = st.sidebar.selectbox( | |
| "Demo Mode", | |
| ["Full Review", "Quick Preview", "Individual Review"], | |
| help="Choose how to run the demo" | |
| ) | |
| # Initialize session state | |
| if 'agent' not in st.session_state: | |
| st.session_state.agent = None | |
| if 'reviewed_applicants' not in st.session_state: | |
| st.session_state.reviewed_applicants = [] | |
| if 'ranked_results' not in st.session_state: | |
| st.session_state.ranked_results = [] | |
| # Main content area | |
| if demo_mode == "Full Review": | |
| st.markdown("## π Full Application Review") | |
| if st.sidebar.button("π Start Full Review", type="primary"): | |
| with st.spinner("Initializing NORA Agent..."): | |
| st.session_state.agent = AdmissionsAgent() | |
| st.success("β Agent initialized successfully!") | |
| # Load and review applications | |
| applicants = load_applications("data/sample_applications.json") | |
| st.markdown("### π Processing Applications...") | |
| progress_bar = st.progress(0) | |
| status_text = st.empty() | |
| reviewed = [] | |
| for idx, applicant in enumerate(applicants, start=1): | |
| status_text.text(f"Reviewing {applicant['name']}...") | |
| with st.spinner(f"Analyzing {applicant['name']}..."): | |
| review = st.session_state.agent.review_applicant(applicant) | |
| reviewed.append((applicant, review)) | |
| progress_bar.progress(idx / len(applicants)) | |
| time.sleep(0.5) # Add slight delay for demo effect | |
| st.session_state.reviewed_applicants = reviewed | |
| st.session_state.ranked_results = st.session_state.agent.rank_all() | |
| st.success(f"β Successfully reviewed {len(applicants)} applicants!") | |
| # Display results if available | |
| if st.session_state.reviewed_applicants: | |
| st.markdown("## π Final Rankings") | |
| # Top 3 highlight | |
| if st.session_state.ranked_results: | |
| top_3 = st.session_state.ranked_results[:3] | |
| col1, col2, col3 = st.columns(3) | |
| with col1: | |
| if len(top_3) > 0: | |
| st.markdown(f""" | |
| <div class="metric-card"> | |
| <h3>π₯ 1st Place</h3> | |
| <h4>{top_3[0]['name']}</h4> | |
| <h2>{top_3[0]['total_score']}/10</h2> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| with col2: | |
| if len(top_3) > 1: | |
| st.markdown(f""" | |
| <div class="metric-card"> | |
| <h3>π₯ 2nd Place</h3> | |
| <h4>{top_3[1]['name']}</h4> | |
| <h2>{top_3[1]['total_score']}/10</h2> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| with col3: | |
| if len(top_3) > 2: | |
| st.markdown(f""" | |
| <div class="metric-card"> | |
| <h3>π₯ 3rd Place</h3> | |
| <h4>{top_3[2]['name']}</h4> | |
| <h2>{top_3[2]['total_score']}/10</h2> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| # Detailed applicant cards | |
| st.markdown("## π Detailed Applicant Reviews") | |
| for i, (applicant, review) in enumerate(st.session_state.reviewed_applicants): | |
| # Find ranking | |
| rank = None | |
| for j, ranked in enumerate(st.session_state.ranked_results, 1): | |
| if ranked['name'] == applicant['name']: | |
| rank = j | |
| break | |
| display_applicant_card(applicant, review, rank) | |
| elif demo_mode == "Quick Preview": | |
| st.markdown("## β‘ Quick Preview") | |
| st.markdown("See a sample of how NORA evaluates applicants without running the full review.") | |
| if st.sidebar.button("π Show Sample Review"): | |
| # Show sample data | |
| sample_applicant = { | |
| "name": "Sample Student", | |
| "gpa": 3.8, | |
| "sat": 1450, | |
| "activities": "Student Council President, Robotics Team Captain", | |
| "essay": "My journey in robotics has taught me the importance of innovation and teamwork...", | |
| "recommendation": "Strong recommendation highlighting leadership and technical skills" | |
| } | |
| sample_review = { | |
| "name": "Sample Student", | |
| "scores": { | |
| "academics": {"score": 8.5, "justification": "Strong GPA and SAT scores"}, | |
| "activities": {"score": 9.0, "justification": "Excellent leadership roles"}, | |
| "essay": {"score": 8.0, "justification": "Well-written and compelling"}, | |
| "recommendations": {"score": 8.5, "justification": "Strong endorsements"} | |
| }, | |
| "total_score": 8.5, | |
| "summary": "Sample Student demonstrates excellent academic performance combined with strong leadership experience. Their robotics involvement shows technical aptitude and teamwork skills." | |
| } | |
| display_applicant_card(sample_applicant, sample_review, 1) | |
| elif demo_mode == "Individual Review": | |
| st.markdown("## π€ Individual Applicant Review") | |
| # Load sample applicants for selection | |
| applicants = load_applications("data/sample_applications.json") | |
| selected_applicant = st.selectbox( | |
| "Choose an applicant to review:", | |
| options=[app['name'] for app in applicants], | |
| format_func=lambda x: x | |
| ) | |
| if st.sidebar.button("π Review Selected Applicant"): | |
| if st.session_state.agent is None: | |
| with st.spinner("Initializing agent..."): | |
| st.session_state.agent = AdmissionsAgent() | |
| # Find the selected applicant | |
| applicant_data = next(app for app in applicants if app['name'] == selected_applicant) | |
| with st.spinner(f"Reviewing {selected_applicant}..."): | |
| review = st.session_state.agent.review_applicant(applicant_data) | |
| st.success(f"β Review completed for {selected_applicant}!") | |
| display_applicant_card(applicant_data, review) | |
| # Footer | |
| st.markdown("---") | |
| st.markdown(""" | |
| <div style="text-align: center; color: #666; font-size: 0.8em;"> | |
| <p>π NORA Admissions Agent - Northeastern University Demo</p> | |
| <p>Powered by Google Gemini AI</p> | |
| </div> | |
| """, unsafe_allow_html=True) | |