Spaces:
Runtime error
Runtime error
Update app/routes.py
Browse files- app/routes.py +17 -8
app/routes.py
CHANGED
|
@@ -53,13 +53,15 @@ def landing():
|
|
| 53 |
return redirect(url_for('auth.dashboard'))
|
| 54 |
return render_template('landing.html')
|
| 55 |
|
| 56 |
-
|
| 57 |
@api.route('/rank-resumes', methods=['GET', 'POST'])
|
| 58 |
def rank_resumes():
|
|
|
|
|
|
|
|
|
|
| 59 |
# 1. Extract and validate API key
|
| 60 |
auth_header = request.headers.get('Authorization')
|
| 61 |
if not auth_header or not auth_header.startswith("Bearer "):
|
| 62 |
-
return
|
| 63 |
|
| 64 |
api_key = auth_header.split(" ")[1]
|
| 65 |
|
|
@@ -68,25 +70,32 @@ def rank_resumes():
|
|
| 68 |
f"{SUPABASE_URL}/rest/v1/users?api_key=eq.{api_key}",
|
| 69 |
headers=HEADERS
|
| 70 |
)
|
| 71 |
-
|
| 72 |
if response.status_code != 200 or not response.json():
|
| 73 |
-
return
|
| 74 |
|
| 75 |
# 3. Parse form data
|
| 76 |
job_description = request.form.get('job_description')
|
| 77 |
resume_files = request.files.getlist('resumes')
|
| 78 |
|
| 79 |
if not job_description:
|
| 80 |
-
return
|
| 81 |
if not resume_files:
|
| 82 |
-
return
|
| 83 |
|
| 84 |
# 4. Rank resumes
|
| 85 |
try:
|
| 86 |
results = rank_resumes_by_semantic_similarity(resume_files, job_description)
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
except Exception as e:
|
| 89 |
-
return
|
|
|
|
|
|
|
| 90 |
|
| 91 |
@auth.route('/register', methods=['GET', 'POST'])
|
| 92 |
def register():
|
|
|
|
| 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 |
|
|
|
|
| 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 |
|
| 100 |
@auth.route('/register', methods=['GET', 'POST'])
|
| 101 |
def register():
|