Spaces:
Running
Running
import os | |
import streamlit as st | |
import pandas as pd | |
import requests | |
# Load the scholarships data | |
def load_scholarships_data(): | |
return pd.read_csv("scholarships_data.csv") | |
# Function to filter scholarships based on user input | |
def recommend_scholarships(data, user_details): | |
filtered_scholarships = [] | |
for _, row in data.iterrows(): | |
eligibility = row["Eligibility"].lower() | |
if ( | |
(user_details["citizenship"] == "india" and "indian" in eligibility) or | |
(user_details["age"] <= 35 and "below 35" in eligibility) or | |
(user_details["income"] <= 250000 and "₹2,50,000" in eligibility) or | |
(user_details["education_level"] in eligibility) or | |
(user_details["category"] in eligibility) | |
): | |
filtered_scholarships.append(row) | |
return pd.DataFrame(filtered_scholarships) | |
# Function to call Gemini API | |
def query_gemini(prompt): | |
gemini_api_key = os.getenv("GEMINI_API_KEY") | |
if not gemini_api_key: | |
st.error("Gemini API Key not found in environment variables.") | |
return None | |
url = "https://api.gemini.com/v1/query" | |
headers = { | |
"Authorization": f"Bearer {gemini_api_key}", | |
"Content-Type": "application/json", | |
} | |
payload = {"prompt": prompt} | |
response = requests.post(url, headers=headers, json=payload) | |
if response.status_code == 200: | |
return response.json().get("response", "") | |
else: | |
return "Error: Unable to fetch response from Gemini API." | |
# Streamlit App | |
def main(): | |
st.title("Scholarship Recommendation System") | |
# User Input Form | |
st.header("Student Scholarship Application Form") | |
with st.form("student_form"): | |
st.subheader("Personal Details") | |
citizenship = st.selectbox("Citizenship", ["India", "Other"]) | |
age = st.number_input("Age", min_value=1, max_value=100) | |
income = st.number_input("Annual Family Income (in ₹)", min_value=0, max_value=10000000) | |
education_level = st.selectbox( | |
"Education Level", | |
["Class 10", "Class 12", "Undergraduate", "Postgraduate", "PhD"] | |
) | |
category = st.selectbox( | |
"Category", | |
["General", "OBC", "SC", "ST", "EWS", "Minority"] | |
) | |
submit_button = st.form_submit_button("Find Scholarships") | |
# Process form submission | |
if submit_button: | |
# Load scholarships data | |
scholarships_data = load_scholarships_data() | |
# Prepare user details | |
user_details = { | |
"citizenship": citizenship.lower(), | |
"age": age, | |
"income": income, | |
"education_level": education_level.lower(), | |
"category": category.lower(), | |
} | |
# Filter scholarships | |
recommended_scholarships = recommend_scholarships(scholarships_data, user_details) | |
# Display results | |
st.subheader("Recommended Scholarships") | |
if not recommended_scholarships.empty: | |
for _, scholarship in recommended_scholarships.iterrows(): | |
st.markdown(f"**{scholarship['Scholarship Name']}**") | |
st.write(f"**Eligibility:** {scholarship['Eligibility']}") | |
st.write(f"**Link:** {scholarship['Link']}") | |
st.write("---") | |
else: | |
st.warning("No scholarships found matching your criteria.") | |
# Ask Gemini for additional advice | |
prompt = ( | |
f"Provide advice for a {age}-year-old {citizenship} citizen with an annual family income of ₹{income}, " | |
f"pursuing {education_level}, belonging to the {category} category, to find suitable scholarships." | |
) | |
gemini_response = query_gemini(prompt) | |
if gemini_response: | |
st.subheader("Additional Advice from Gemini") | |
st.write(gemini_response) | |
if __name__ == "__main__": | |
main() |