Akshayram1 commited on
Commit
8b5a437
·
verified ·
1 Parent(s): 20d92a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -40
app.py CHANGED
@@ -6,7 +6,6 @@ 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
  # Load scholarships data
11
  @st.cache_data
12
  def load_scholarships():
@@ -18,6 +17,15 @@ def load_scholarships():
18
  st.stop()
19
  return scholarships
20
 
 
 
 
 
 
 
 
 
 
21
  # Recommendation engine
22
  def recommend_scholarships(user_data, scholarships):
23
  matches = []
@@ -33,30 +41,6 @@ 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:
@@ -78,14 +62,19 @@ def main():
78
  citizenship = st.selectbox("Citizenship", ["India", "Other"]).lower()
79
  age = st.number_input("Age", 1, 100, 25)
80
  income = st.number_input("Annual Family Income (₹)", 0, 10000000, 500000)
81
- education = st.selectbox("Education Level",
82
- ["Class 10", "Class 12", "Undergraduate",
83
- "Postgraduate", "PhD"]).lower()
84
- category = st.selectbox("Category",
85
- ["General", "OBC", "SC", "ST", "EWS", "Minority"]).lower()
86
-
87
- submitted = st.form_submit_button("Find Scholarships")
 
 
 
 
88
 
 
89
  if submitted:
90
  # Validate inputs
91
  if not os.environ.get('GOOGLE_API_KEY'):
@@ -104,14 +93,17 @@ def main():
104
  results = recommend_scholarships(user_data, scholarships)
105
 
106
  # Display results
107
- st.subheader(f"Found {len(results)} Matching Scholarships")
108
- for _, row in results.iterrows():
109
- st.markdown(f"""
110
- **{row['Scholarship Name']}**
111
- **Eligibility:** {row['Eligibility']}
112
- [Apply Here]({row['Link']})
113
- """)
114
- st.divider()
 
 
 
115
 
116
  # Generate AI-powered advice
117
  model = get_genai_client()
 
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():
 
17
  st.stop()
18
  return scholarships
19
 
20
+ # Initialize Generative AI
21
+ def get_genai_client():
22
+ try:
23
+ genai.configure(api_key=os.environ['GOOGLE_API_KEY'])
24
+ return genai.GenerativeModel('gemini-pro')
25
+ except Exception as e:
26
+ st.error(f"AI Initialization Error: {str(e)}")
27
+ return None
28
+
29
  # Recommendation engine
30
  def recommend_scholarships(user_data, scholarships):
31
  matches = []
 
41
  matches.append(row)
42
  return pd.DataFrame(matches)
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  # Helper functions for eligibility parsing
45
  def parse_age(eligibility):
46
  if 'below 35' in eligibility:
 
62
  citizenship = st.selectbox("Citizenship", ["India", "Other"]).lower()
63
  age = st.number_input("Age", 1, 100, 25)
64
  income = st.number_input("Annual Family Income (₹)", 0, 10000000, 500000)
65
+ education = st.selectbox(
66
+ "Education Level",
67
+ ["Class 10", "Class 12", "Undergraduate",
68
+ "Postgraduate", "PhD"]
69
+ ).lower()
70
+ category = st.selectbox(
71
+ "Category",
72
+ ["General", "OBC", "SC", "ST", "EWS", "Minority"]
73
+ ).lower()
74
+
75
+ submitted = st.form_submit_button("Find Scholarships") # Form submission button
76
 
77
+ # Process form submission
78
  if submitted:
79
  # Validate inputs
80
  if not os.environ.get('GOOGLE_API_KEY'):
 
93
  results = recommend_scholarships(user_data, scholarships)
94
 
95
  # Display results
96
+ if not results.empty:
97
+ st.subheader(f"Found {len(results)} Matching Scholarships")
98
+ for _, row in results.iterrows():
99
+ st.markdown(f"""
100
+ **{row['Scholarship Name']}**
101
+ **Eligibility:** {row['Eligibility']}
102
+ [Apply Here]({row['Link']})
103
+ """)
104
+ st.divider()
105
+ else:
106
+ st.warning("No scholarships found matching your criteria.")
107
 
108
  # Generate AI-powered advice
109
  model = get_genai_client()