import streamlit as st import pandas as pd import re from datetime import datetime from typing import List # Page configuration st.set_page_config( page_title="Scholarship Search (Context Based Search)", page_icon="🎓", layout="wide" ) # Load and prepare data @st.cache_data def load_scholarships(): try: df = pd.read_csv("scholarships_data.csv", quotechar='"', quoting=1) df = df.map(lambda x: x.strip() if isinstance(x, str) else x) df.rename(columns=lambda x: x.strip(), inplace=True) return df except Exception as e: st.error(f"Error loading data: {str(e)}") st.stop() # Custom CSS for styling def load_css(): st.markdown(""" """, unsafe_allow_html=True) # Format the deadline status def format_deadline(deadline_str): try: if not deadline_str or pd.isna(deadline_str) or deadline_str == "N/A": return "Open - No specific deadline", "#00b894" # Handle different date formats try: deadline = datetime.strptime(deadline_str, "%d-%m-%Y") except ValueError: try: deadline = datetime.strptime(deadline_str, "%Y-%m-%d") except ValueError: return deadline_str, "#00b894" today = datetime.now() days_left = (deadline - today).days if days_left < 0: return "Expired", "#e74c3c" elif days_left <= 7: return f"{days_left} days left!", "#ff7675" elif days_left <= 30: return f"{days_left} days left", "#00b894" else: return f"{days_left} days left", "#3498db" except: return deadline_str, "#00b894" # Highlight search terms in text def highlight_text(text, search_terms): if not search_terms or not text: return text # Convert search terms to a list if it's a string if isinstance(search_terms, str): search_terms = [search_terms] # Highlight each search term for term in search_terms: if term.strip(): pattern = re.compile(re.escape(term.strip()), re.IGNORECASE) text = pattern.sub(f'{term}', text) return text # Display scholarship results def display_scholarships(df: pd.DataFrame, search_terms: List[str] = None) -> None: if df.empty: st.markdown('