Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import requests
|
| 5 |
+
|
| 6 |
+
# Load the scholarships data
|
| 7 |
+
@st.cache_data
|
| 8 |
+
def load_scholarships_data():
|
| 9 |
+
return pd.read_csv("scholarships_data.csv")
|
| 10 |
+
|
| 11 |
+
# Function to filter scholarships based on user input
|
| 12 |
+
def recommend_scholarships(data, user_details):
|
| 13 |
+
filtered_scholarships = []
|
| 14 |
+
for _, row in data.iterrows():
|
| 15 |
+
eligibility = row["Eligibility"].lower()
|
| 16 |
+
if (
|
| 17 |
+
(user_details["citizenship"] == "india" and "indian" in eligibility) or
|
| 18 |
+
(user_details["age"] <= 35 and "below 35" in eligibility) or
|
| 19 |
+
(user_details["income"] <= 250000 and "₹2,50,000" in eligibility) or
|
| 20 |
+
(user_details["education_level"] in eligibility) or
|
| 21 |
+
(user_details["category"] in eligibility)
|
| 22 |
+
):
|
| 23 |
+
filtered_scholarships.append(row)
|
| 24 |
+
return pd.DataFrame(filtered_scholarships)
|
| 25 |
+
|
| 26 |
+
# Function to call Gemini API
|
| 27 |
+
def query_gemini(prompt):
|
| 28 |
+
gemini_api_key = os.getenv("GEMINI_API_KEY")
|
| 29 |
+
if not gemini_api_key:
|
| 30 |
+
st.error("Gemini API Key not found in environment variables.")
|
| 31 |
+
return None
|
| 32 |
+
|
| 33 |
+
url = "https://api.gemini.com/v1/query"
|
| 34 |
+
headers = {
|
| 35 |
+
"Authorization": f"Bearer {gemini_api_key}",
|
| 36 |
+
"Content-Type": "application/json",
|
| 37 |
+
}
|
| 38 |
+
payload = {"prompt": prompt}
|
| 39 |
+
response = requests.post(url, headers=headers, json=payload)
|
| 40 |
+
if response.status_code == 200:
|
| 41 |
+
return response.json().get("response", "")
|
| 42 |
+
else:
|
| 43 |
+
return "Error: Unable to fetch response from Gemini API."
|
| 44 |
+
|
| 45 |
+
# Streamlit App
|
| 46 |
+
def main():
|
| 47 |
+
st.title("Scholarship Recommendation System")
|
| 48 |
+
|
| 49 |
+
# User Input Form
|
| 50 |
+
st.header("Student Scholarship Application Form")
|
| 51 |
+
with st.form("student_form"):
|
| 52 |
+
st.subheader("Personal Details")
|
| 53 |
+
citizenship = st.selectbox("Citizenship", ["India", "Other"])
|
| 54 |
+
age = st.number_input("Age", min_value=1, max_value=100)
|
| 55 |
+
income = st.number_input("Annual Family Income (in ₹)", min_value=0, max_value=10000000)
|
| 56 |
+
education_level = st.selectbox(
|
| 57 |
+
"Education Level",
|
| 58 |
+
["Class 10", "Class 12", "Undergraduate", "Postgraduate", "PhD"]
|
| 59 |
+
)
|
| 60 |
+
category = st.selectbox(
|
| 61 |
+
"Category",
|
| 62 |
+
["General", "OBC", "SC", "ST", "EWS", "Minority"]
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
submit_button = st.form_submit_button("Find Scholarships")
|
| 66 |
+
|
| 67 |
+
# Process form submission
|
| 68 |
+
if submit_button:
|
| 69 |
+
# Load scholarships data
|
| 70 |
+
scholarships_data = load_scholarships_data()
|
| 71 |
+
|
| 72 |
+
# Prepare user details
|
| 73 |
+
user_details = {
|
| 74 |
+
"citizenship": citizenship.lower(),
|
| 75 |
+
"age": age,
|
| 76 |
+
"income": income,
|
| 77 |
+
"education_level": education_level.lower(),
|
| 78 |
+
"category": category.lower(),
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
# Filter scholarships
|
| 82 |
+
recommended_scholarships = recommend_scholarships(scholarships_data, user_details)
|
| 83 |
+
|
| 84 |
+
# Display results
|
| 85 |
+
st.subheader("Recommended Scholarships")
|
| 86 |
+
if not recommended_scholarships.empty:
|
| 87 |
+
for _, scholarship in recommended_scholarships.iterrows():
|
| 88 |
+
st.markdown(f"**{scholarship['Scholarship Name']}**")
|
| 89 |
+
st.write(f"**Eligibility:** {scholarship['Eligibility']}")
|
| 90 |
+
st.write(f"**Link:** {scholarship['Link']}")
|
| 91 |
+
st.write("---")
|
| 92 |
+
else:
|
| 93 |
+
st.warning("No scholarships found matching your criteria.")
|
| 94 |
+
|
| 95 |
+
# Ask Gemini for additional advice
|
| 96 |
+
prompt = (
|
| 97 |
+
f"Provide advice for a {age}-year-old {citizenship} citizen with an annual family income of ₹{income}, "
|
| 98 |
+
f"pursuing {education_level}, belonging to the {category} category, to find suitable scholarships."
|
| 99 |
+
)
|
| 100 |
+
gemini_response = query_gemini(prompt)
|
| 101 |
+
if gemini_response:
|
| 102 |
+
st.subheader("Additional Advice from Gemini")
|
| 103 |
+
st.write(gemini_response)
|
| 104 |
+
|
| 105 |
+
if __name__ == "__main__":
|
| 106 |
+
main()
|