Spaces:
Sleeping
Sleeping
File size: 4,395 Bytes
a442f53 f70d963 a442f53 f70d963 a442f53 f70d963 20d92a5 f70d963 8b5a437 f70d963 a442f53 f70d963 a442f53 f70d963 a442f53 f70d963 a442f53 f70d963 a442f53 f70d963 a442f53 f70d963 8b5a437 a442f53 8b5a437 f70d963 a442f53 f70d963 a442f53 f70d963 a442f53 8b5a437 a442f53 f70d963 a442f53 |
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 |
import os
import streamlit as st
import pandas as pd
import google.generativeai as genai
# Configuration
os.environ['GOOGLE_API_KEY'] = os.getenv('GOOGLE_API_KEY', 'your_key_here')
# Load scholarships data
@st.cache_data
def load_scholarships():
scholarships = pd.read_csv("scholarships_data.csv")
scholarships.rename(columns=lambda x: x.strip(), inplace=True) # Clean column names
required_columns = ['Scholarship Name', 'Eligibility', 'Link']
if not all(col in scholarships.columns for col in required_columns):
st.error(f"Missing required columns in the CSV file: {required_columns}")
st.stop()
return scholarships
# Initialize Generative AI
def get_genai_client():
try:
genai.configure(api_key=os.environ['GOOGLE_API_KEY'])
return genai.GenerativeModel('gemini-pro')
except Exception as e:
st.error(f"AI Initialization Error: {str(e)}")
return None
# Recommendation engine
def recommend_scholarships(user_data, scholarships):
matches = []
for _, row in scholarships.iterrows():
eligibility = row['Eligibility'].lower()
if (
(user_data['citizenship'] in eligibility) and
(user_data['age'] <= parse_age(eligibility)) and
(user_data['income'] <= parse_income(eligibility)) and
(user_data['education'] in eligibility) and
(user_data['category'] in eligibility)
):
matches.append(row)
return pd.DataFrame(matches)
# Helper functions for eligibility parsing
def parse_age(eligibility):
if 'below 35' in eligibility:
return 35
return 100 # Default if no age restriction
def parse_income(eligibility):
if '₹2,50,000' in eligibility:
return 250000
return float('inf') # Default if no income restriction
# Streamlit app
def main():
st.title("AI-Powered Scholarship Advisor")
# User input form
with st.form("scholarship_form"):
st.header("Student Profile")
citizenship = st.selectbox("Citizenship", ["India", "Other"]).lower()
age = st.number_input("Age", 1, 100, 25)
income = st.number_input("Annual Family Income (₹)", 0, 10000000, 500000)
education = st.selectbox(
"Education Level",
["Class 10", "Class 12", "Undergraduate",
"Postgraduate", "PhD"]
).lower()
category = st.selectbox(
"Category",
["General", "OBC", "SC", "ST", "EWS", "Minority"]
).lower()
submitted = st.form_submit_button("Find Scholarships") # Form submission button
# Process form submission
if submitted:
# Validate inputs
if not os.environ.get('GOOGLE_API_KEY'):
st.warning("Please set GOOGLE_API_KEY environment variable")
return
# Load data and generate recommendations
scholarships = load_scholarships()
user_data = {
'citizenship': citizenship,
'age': age,
'income': income,
'education': education,
'category': category
}
results = recommend_scholarships(user_data, scholarships)
# Display results
if not results.empty:
st.subheader(f"Found {len(results)} Matching Scholarships")
for _, row in results.iterrows():
st.markdown(f"""
**{row['Scholarship Name']}**
**Eligibility:** {row['Eligibility']}
[Apply Here]({row['Link']})
""")
st.divider()
else:
st.warning("No scholarships found matching your criteria.")
# Generate AI-powered advice
model = get_genai_client()
if model:
prompt = f"""
Act as an experienced education counselor.
For a {age}-year-old {citizenship} citizen with:
- Annual income: ₹{income}
- Education level: {education}
- Category: {category}
Provide personalized advice about these scholarships:
{results['Scholarship Name'].tolist()}
"""
response = model.generate_content(prompt)
st.subheader("AI Advisor Recommendations")
st.write(response.text)
if __name__ == "__main__":
main() |