Spaces:
Sleeping
Sleeping
Upload job_matching.py
Browse files- src/job_matching.py +35 -0
src/job_matching.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
| 2 |
+
import numpy as np
|
| 3 |
+
from chroma_utils import search_resume_chroma
|
| 4 |
+
|
| 5 |
+
def calculate_ats_score(job_embedding):
|
| 6 |
+
|
| 7 |
+
try:
|
| 8 |
+
|
| 9 |
+
search_results = search_resume_chroma(job_embedding, k=10)
|
| 10 |
+
candidate_ids = search_results['ids'][0]
|
| 11 |
+
candidate_embeddings = search_results['embeddings'][0]
|
| 12 |
+
candidate_metadatas = search_results['metadatas'][0]
|
| 13 |
+
|
| 14 |
+
matched_candidates = []
|
| 15 |
+
for i, candidate_id in enumerate(candidate_ids):
|
| 16 |
+
|
| 17 |
+
candidate_metadata = candidate_metadatas[i]
|
| 18 |
+
candidate_embedding = np.array(candidate_embeddings[i])
|
| 19 |
+
|
| 20 |
+
similarity_score = cosine_similarity([job_embedding], [candidate_embedding])[0][0]
|
| 21 |
+
|
| 22 |
+
matched_candidates.append({
|
| 23 |
+
"candidate_id": candidate_id,
|
| 24 |
+
"score": similarity_score,
|
| 25 |
+
"metadata": candidate_metadata
|
| 26 |
+
})
|
| 27 |
+
|
| 28 |
+
matched_candidates.sort(key=lambda x: x["score"], reverse=True)
|
| 29 |
+
return matched_candidates
|
| 30 |
+
except Exception:
|
| 31 |
+
raise
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
|