Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,19 +6,17 @@ import google.generativeai as genai
|
|
| 6 |
# Configuration
|
| 7 |
os.environ['GOOGLE_API_KEY'] = os.getenv('GOOGLE_API_KEY', 'your_key_here')
|
| 8 |
|
|
|
|
| 9 |
# Load scholarships data
|
| 10 |
@st.cache_data
|
| 11 |
def load_scholarships():
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
except Exception as e:
|
| 20 |
-
st.error(f"AI Initialization Error: {str(e)}")
|
| 21 |
-
return None
|
| 22 |
|
| 23 |
# Recommendation engine
|
| 24 |
def recommend_scholarships(user_data, scholarships):
|
|
@@ -35,6 +33,30 @@ def recommend_scholarships(user_data, scholarships):
|
|
| 35 |
matches.append(row)
|
| 36 |
return pd.DataFrame(matches)
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
# Helper functions for eligibility parsing
|
| 39 |
def parse_age(eligibility):
|
| 40 |
if 'below 35' in eligibility:
|
|
|
|
| 6 |
# Configuration
|
| 7 |
os.environ['GOOGLE_API_KEY'] = os.getenv('GOOGLE_API_KEY', 'your_key_here')
|
| 8 |
|
| 9 |
+
# Load scholarships data
|
| 10 |
# Load scholarships data
|
| 11 |
@st.cache_data
|
| 12 |
def load_scholarships():
|
| 13 |
+
scholarships = pd.read_csv("scholarships_data.csv")
|
| 14 |
+
scholarships.rename(columns=lambda x: x.strip(), inplace=True) # Clean column names
|
| 15 |
+
required_columns = ['Scholarship Name', 'Eligibility', 'Link']
|
| 16 |
+
if not all(col in scholarships.columns for col in required_columns):
|
| 17 |
+
st.error(f"Missing required columns in the CSV file: {required_columns}")
|
| 18 |
+
st.stop()
|
| 19 |
+
return scholarships
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# Recommendation engine
|
| 22 |
def recommend_scholarships(user_data, scholarships):
|
|
|
|
| 33 |
matches.append(row)
|
| 34 |
return pd.DataFrame(matches)
|
| 35 |
|
| 36 |
+
# Display results
|
| 37 |
+
if submitted:
|
| 38 |
+
scholarships = load_scholarships()
|
| 39 |
+
user_data = {
|
| 40 |
+
'citizenship': citizenship,
|
| 41 |
+
'age': age,
|
| 42 |
+
'income': income,
|
| 43 |
+
'education': education,
|
| 44 |
+
'category': category
|
| 45 |
+
}
|
| 46 |
+
results = recommend_scholarships(user_data, scholarships)
|
| 47 |
+
|
| 48 |
+
if not results.empty:
|
| 49 |
+
st.subheader(f"Found {len(results)} Matching Scholarships")
|
| 50 |
+
for _, row in results.iterrows():
|
| 51 |
+
st.markdown(f"""
|
| 52 |
+
**{row['Scholarship Name']}**
|
| 53 |
+
**Eligibility:** {row['Eligibility']}
|
| 54 |
+
[Apply Here]({row['Link']})
|
| 55 |
+
""")
|
| 56 |
+
st.divider()
|
| 57 |
+
else:
|
| 58 |
+
st.warning("No scholarships found matching your criteria.")
|
| 59 |
+
|
| 60 |
# Helper functions for eligibility parsing
|
| 61 |
def parse_age(eligibility):
|
| 62 |
if 'below 35' in eligibility:
|