msgasu commited on
Commit
053cdda
·
verified ·
1 Parent(s): dc945d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -6
app.py CHANGED
@@ -31,8 +31,10 @@ except Exception as e:
31
 
32
  # Define all_traits dictionary (needed for preprocessing)
33
  all_traits = {
34
- 'Interests': set(['Reading', 'Dancing', 'Physics', 'Research', 'Cooking', 'Art', 'Playing Football', 'Creativity', 'Writing']),
35
- 'Strengths': set(['Communication', 'Creativity', 'Logical Reasoning', 'Innovative Thinking', 'Teamwork', 'Hands-on Skills', 'Analytical Thinking'])
 
 
36
  }
37
 
38
  # Function to convert grades to numerical values
@@ -93,7 +95,9 @@ def prepare_model_data(processed_df):
93
  # Identify categorical and numerical features
94
  categorical_features = ["Desired_Career"]
95
  numerical_features = ["Aggregate", "English", "Core Maths", "Science", "Social Studies",
96
- "Physics", "Biology", "Elective Maths", "Chemistry"]
 
 
97
 
98
  # Add the binary interest and strength columns
99
  interest_strength_cols = [col for col in processed_df.columns if col.startswith('interest_') or col.startswith('strength_')]
@@ -102,6 +106,9 @@ def prepare_model_data(processed_df):
102
  for col in numerical_features:
103
  if col in processed_df.columns: # Check if column exists
104
  processed_df[col] = processed_df[col].apply(grade_to_numeric)
 
 
 
105
 
106
  # Get features (using processed_df with numerical grades)
107
  X = processed_df[categorical_features + numerical_features + interest_strength_cols]
@@ -181,7 +188,7 @@ def predict_career(desired_career, aggregate, interests, strengths, english, cor
181
  elective_maths, physics, biology, chemistry):
182
 
183
  try:
184
- # Create student data dictionary
185
  student_info = {
186
  "StudentID": "STU_TEMP",
187
  "Desired_Career": desired_career,
@@ -196,7 +203,15 @@ def predict_career(desired_career, aggregate, interests, strengths, english, cor
196
  "Elective Maths": elective_maths,
197
  "Physics": physics,
198
  "Biology": biology,
199
- "Chemistry": chemistry
 
 
 
 
 
 
 
 
200
  }
201
 
202
  # Get recommendations
@@ -216,7 +231,9 @@ def predict_career(desired_career, aggregate, interests, strengths, english, cor
216
 
217
  return recommendations + "\n" + explanation
218
  except Exception as e:
219
- return f"Error processing request: {str(e)}"
 
 
220
 
221
  # Define grade options - fixing format to work with Gradio
222
  grade_options = [
 
31
 
32
  # Define all_traits dictionary (needed for preprocessing)
33
  all_traits = {
34
+ 'Interests': set(['Reading', 'Dancing', 'Physics', 'Research', 'Cooking', 'Art', 'Playing Football', 'Creativity', 'Writing',
35
+ 'Technology', 'Public Speaking', 'Music', 'Mathematics', 'Leadership', 'Problem-Solving', 'Entrepreneurship']),
36
+ 'Strengths': set(['Communication', 'Creativity', 'Logical Reasoning', 'Innovative Thinking', 'Teamwork', 'Hands-on Skills',
37
+ 'Analytical Thinking', 'Leadership', 'Detail-Oriented'])
38
  }
39
 
40
  # Function to convert grades to numerical values
 
95
  # Identify categorical and numerical features
96
  categorical_features = ["Desired_Career"]
97
  numerical_features = ["Aggregate", "English", "Core Maths", "Science", "Social Studies",
98
+ "Physics", "Biology", "Elective Maths", "Chemistry",
99
+ "Economics", "E-ICT", "Literature", "Geography",
100
+ "Business Management", "Visual Arts", "Government"]
101
 
102
  # Add the binary interest and strength columns
103
  interest_strength_cols = [col for col in processed_df.columns if col.startswith('interest_') or col.startswith('strength_')]
 
106
  for col in numerical_features:
107
  if col in processed_df.columns: # Check if column exists
108
  processed_df[col] = processed_df[col].apply(grade_to_numeric)
109
+ else:
110
+ # Add missing columns with NaN values
111
+ processed_df[col] = np.nan
112
 
113
  # Get features (using processed_df with numerical grades)
114
  X = processed_df[categorical_features + numerical_features + interest_strength_cols]
 
188
  elective_maths, physics, biology, chemistry):
189
 
190
  try:
191
+ # Create student data dictionary with all required fields
192
  student_info = {
193
  "StudentID": "STU_TEMP",
194
  "Desired_Career": desired_career,
 
203
  "Elective Maths": elective_maths,
204
  "Physics": physics,
205
  "Biology": biology,
206
+ "Chemistry": chemistry,
207
+ # Add empty values for other subjects that were in the training data
208
+ "Economics": "",
209
+ "E-ICT": "",
210
+ "Literature": "",
211
+ "Geography": "",
212
+ "Business Management": "",
213
+ "Visual Arts": "",
214
+ "Government": ""
215
  }
216
 
217
  # Get recommendations
 
231
 
232
  return recommendations + "\n" + explanation
233
  except Exception as e:
234
+ import traceback
235
+ error_details = traceback.format_exc()
236
+ return f"Error processing request: {str(e)}\n\nDetails:\n{error_details}"
237
 
238
  # Define grade options - fixing format to work with Gradio
239
  grade_options = [