Spaces:
Runtime error
Runtime error
Update app/utils.py
Browse files- app/utils.py +28 -7
app/utils.py
CHANGED
|
@@ -2,6 +2,12 @@ import fitz # PyMuPDF
|
|
| 2 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
| 3 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
def extract_text_from_pdf(file_storage):
|
| 6 |
with fitz.open(stream=file_storage.read(), filetype="pdf") as doc:
|
| 7 |
return " ".join([page.get_text() for page in doc])
|
|
@@ -25,10 +31,8 @@ def rank_resumes_by_similarity(resume_files, job_description):
|
|
| 25 |
]
|
| 26 |
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
from flask import request, jsonify
|
| 31 |
-
from .models import User # adjust import to your structure
|
| 32 |
|
| 33 |
def require_api_key(f):
|
| 34 |
@wraps(f)
|
|
@@ -40,10 +44,27 @@ def require_api_key(f):
|
|
| 40 |
|
| 41 |
token = auth_header.split("Bearer ")[1].strip()
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
return jsonify({"error": "Invalid or revoked API key."}), 403
|
| 46 |
|
| 47 |
-
|
|
|
|
|
|
|
| 48 |
return f(*args, **kwargs)
|
| 49 |
return decorated_function
|
|
|
|
| 2 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
| 3 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 4 |
|
| 5 |
+
import os
|
| 6 |
+
import requests
|
| 7 |
+
from functools import wraps
|
| 8 |
+
from flask import request, jsonify
|
| 9 |
+
|
| 10 |
+
|
| 11 |
def extract_text_from_pdf(file_storage):
|
| 12 |
with fitz.open(stream=file_storage.read(), filetype="pdf") as doc:
|
| 13 |
return " ".join([page.get_text() for page in doc])
|
|
|
|
| 31 |
]
|
| 32 |
|
| 33 |
|
| 34 |
+
SUPABASE_URL = os.getenv("SUPABASE_URL")
|
| 35 |
+
SUPABASE_API_KEY = os.getenv("SUPABASE_API_KEY")
|
|
|
|
|
|
|
| 36 |
|
| 37 |
def require_api_key(f):
|
| 38 |
@wraps(f)
|
|
|
|
| 44 |
|
| 45 |
token = auth_header.split("Bearer ")[1].strip()
|
| 46 |
|
| 47 |
+
# Call Supabase REST API to validate token
|
| 48 |
+
headers = {
|
| 49 |
+
"apikey": SUPABASE_API_KEY,
|
| 50 |
+
"Authorization": f"Bearer {SUPABASE_API_KEY}", # service role
|
| 51 |
+
"Content-Type": "application/json"
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
url = f"{SUPABASE_URL}/rest/v1/users?api_key=eq.{token}"
|
| 55 |
+
|
| 56 |
+
response = requests.get(url, headers=headers)
|
| 57 |
+
|
| 58 |
+
if response.status_code != 200:
|
| 59 |
+
return jsonify({"error": "Failed to contact Supabase"}), 500
|
| 60 |
+
|
| 61 |
+
user_data = response.json()
|
| 62 |
+
|
| 63 |
+
if not user_data:
|
| 64 |
return jsonify({"error": "Invalid or revoked API key."}), 403
|
| 65 |
|
| 66 |
+
# Optionally attach user to request (like before)
|
| 67 |
+
request.user = user_data[0]
|
| 68 |
+
|
| 69 |
return f(*args, **kwargs)
|
| 70 |
return decorated_function
|