File size: 3,913 Bytes
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
import os
import streamlit as st
import pandas as pd
import requests

# Load the scholarships data
@st.cache_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()