webcodelab commited on
Commit
3a5839c
·
verified ·
1 Parent(s): 638497c

Update app/routes.py

Browse files
Files changed (1) hide show
  1. app/routes.py +59 -30
app/routes.py CHANGED
@@ -53,47 +53,76 @@ def landing():
53
  return redirect(url_for('auth.dashboard'))
54
  return render_template('landing.html')
55
 
56
- @api.route('/rank-resumes', methods=['GET', 'POST'])
57
- def rank_resumes():
58
- if request.method == 'GET':
59
- return render_template("upload_rank_form.html") # Optional: A form to test this route manually
60
 
61
- # 1. Extract and validate API key
62
- auth_header = request.headers.get('Authorization')
63
- if not auth_header or not auth_header.startswith("Bearer "):
64
- return render_template("error.html", error="Missing or invalid Authorization header"), 401
65
 
66
- api_key = auth_header.split(" ")[1]
67
 
68
- # 2. Query Supabase to validate API key
69
- response = requests.get(
70
- f"{SUPABASE_URL}/rest/v1/users?api_key=eq.{api_key}",
71
- headers=HEADERS
72
- )
73
- if response.status_code != 200 or not response.json():
74
- return render_template("error.html", error="Invalid API key"), 403
75
 
76
- # 3. Parse form data
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  job_description = request.form.get('job_description')
78
  resume_files = request.files.getlist('resumes')
79
 
80
- if not job_description:
81
- return render_template("error.html", error="Missing job description"), 400
82
- if not resume_files:
83
- return render_template("error.html", error="No resumes uploaded"), 400
84
 
85
- # 4. Rank resumes
86
- try:
87
- results = rank_resumes_by_semantic_similarity(resume_files, job_description)
 
 
88
 
89
- return render_template(
90
- "resume_rankings.html",
91
- job_description=job_description,
92
- ranked_resumes=results
93
- )
94
 
 
 
95
  except Exception as e:
96
- return render_template("error.html", error=f"Error processing resumes: {str(e)}"), 500
 
 
 
97
 
98
 
99
 
 
53
  return redirect(url_for('auth.dashboard'))
54
  return render_template('landing.html')
55
 
56
+ # @api.route('/rank-resumes', methods=['GET', 'POST'])
57
+ # def rank_resumes():
58
+ # if request.method == 'GET':
59
+ # return render_template("upload_rank_form.html") # Optional: A form to test this route manually
60
 
61
+ # # 1. Extract and validate API key
62
+ # auth_header = request.headers.get('Authorization')
63
+ # if not auth_header or not auth_header.startswith("Bearer "):
64
+ # return render_template("error.html", error="Missing or invalid Authorization header"), 401
65
 
66
+ # api_key = auth_header.split(" ")[1]
67
 
68
+ # # 2. Query Supabase to validate API key
69
+ # response = requests.get(
70
+ # f"{SUPABASE_URL}/rest/v1/users?api_key=eq.{api_key}",
71
+ # headers=HEADERS
72
+ # )
73
+ # if response.status_code != 200 or not response.json():
74
+ # return render_template("error.html", error="Invalid API key"), 403
75
 
76
+ # # 3. Parse form data
77
+ # job_description = request.form.get('job_description')
78
+ # resume_files = request.files.getlist('resumes')
79
+
80
+ # if not job_description:
81
+ # return render_template("error.html", error="Missing job description"), 400
82
+ # if not resume_files:
83
+ # return render_template("error.html", error="No resumes uploaded"), 400
84
+
85
+ # # 4. Rank resumes
86
+ # try:
87
+ # results = rank_resumes_by_semantic_similarity(resume_files, job_description)
88
+
89
+ # return render_template(
90
+ # "resume_rankings.html",
91
+ # job_description=job_description,
92
+ # ranked_resumes=results
93
+ # )
94
+
95
+ # except Exception as e:
96
+ # return render_template("error.html", error=f"Error processing resumes: {str(e)}"), 500
97
+
98
+
99
+ @auth.route('/rank-resumes', methods=['POST'])
100
+ def rank_resumes_page():
101
+ api_key = request.form.get('api_key')
102
  job_description = request.form.get('job_description')
103
  resume_files = request.files.getlist('resumes')
104
 
105
+ if not api_key or not job_description or not resume_files:
106
+ flash("All fields are required.")
107
+ return redirect(url_for('auth.upload_rank_form'))
 
108
 
109
+ # Validate API key with Supabase
110
+ response = requests.get(
111
+ f"{SUPABASE_URL}/rest/v1/users?api_key=eq.{api_key}",
112
+ headers=HEADERS
113
+ )
114
 
115
+ if response.status_code != 200 or not response.json():
116
+ flash("Invalid API key.")
117
+ return redirect(url_for('auth.upload_rank_form'))
 
 
118
 
119
+ try:
120
+ rankings = rank_resumes_by_semantic_similarity(resume_files, job_description)
121
  except Exception as e:
122
+ flash(f"Ranking error: {str(e)}")
123
+ return redirect(url_for('auth.upload_rank_form'))
124
+
125
+ return render_template('resume_rankings.html', rankings=rankings, job_description=job_description)
126
 
127
 
128