Pushpak21 commited on
Commit
a2cb479
·
verified ·
1 Parent(s): 8f7d281

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -1
app.py CHANGED
@@ -35,6 +35,9 @@ def predict():
35
  if missing:
36
  return jsonify({"error": f"Missing fields: {missing}"}), 400
37
 
 
 
 
38
  # Build DataFrame
39
  df = pd.DataFrame([{
40
  'Category': data['Category'],
@@ -54,7 +57,6 @@ def predict():
54
  X_query["Rank_log"] = df["Rank_log"]
55
  X_query["Percentage_bin"] = df["Percentage_bin"]
56
 
57
- # Ensure all training columns exist
58
  for col in feature_columns:
59
  if col not in X_query.columns:
60
  X_query[col] = 0
@@ -81,6 +83,7 @@ def predict():
81
  row = choice_code_map.loc[int(choice_code)]
82
  college_name = row['College Name']
83
  course_name = row['Course Name']
 
84
  results.append({
85
  "rank": rank,
86
  "choice_code": int(choice_code),
@@ -89,6 +92,13 @@ def predict():
89
  "probability_percent": round(float(prob), 2)
90
  })
91
 
 
 
 
 
 
 
 
92
  return jsonify({"top_20_predictions": results})
93
 
94
  except Exception as e:
 
35
  if missing:
36
  return jsonify({"error": f"Missing fields: {missing}"}), 400
37
 
38
+ # Optional field
39
+ desired_location = data.get("Location") # None if not given
40
+
41
  # Build DataFrame
42
  df = pd.DataFrame([{
43
  'Category': data['Category'],
 
57
  X_query["Rank_log"] = df["Rank_log"]
58
  X_query["Percentage_bin"] = df["Percentage_bin"]
59
 
 
60
  for col in feature_columns:
61
  if col not in X_query.columns:
62
  X_query[col] = 0
 
83
  row = choice_code_map.loc[int(choice_code)]
84
  college_name = row['College Name']
85
  course_name = row['Course Name']
86
+
87
  results.append({
88
  "rank": rank,
89
  "choice_code": int(choice_code),
 
92
  "probability_percent": round(float(prob), 2)
93
  })
94
 
95
+ # 🔷 Filter by Location if provided
96
+ if desired_location:
97
+ results = [
98
+ r for r in results
99
+ if desired_location.lower() in r["college_name"].lower()
100
+ ]
101
+
102
  return jsonify({"top_20_predictions": results})
103
 
104
  except Exception as e: