Update main.py
Browse files
main.py
CHANGED
|
@@ -206,18 +206,15 @@ async def extract_resume_and_search(file: UploadFile = File(...)):
|
|
| 206 |
n_results=random.randint(5, 7) # Match your existing search logic
|
| 207 |
)
|
| 208 |
|
| 209 |
-
# Process results (
|
| 210 |
recommendations = []
|
| 211 |
ids = results.get('ids', [[]])[0]
|
| 212 |
distances = results.get('distances', [[]])[0]
|
| 213 |
|
| 214 |
-
# Convert cosine distances to similarity scores (0-1 range)
|
| 215 |
for i, internship_id in enumerate(ids):
|
| 216 |
-
# Clamp the score to ensure it's between 0 and 1
|
| 217 |
-
similarity_score = max(0.0, min(1.0, 1 - distances[i]))
|
| 218 |
recommendations.append({
|
| 219 |
"internship_id": internship_id,
|
| 220 |
-
"score":
|
| 221 |
})
|
| 222 |
|
| 223 |
print(f"✅ Found {len(recommendations)} recommendations for resume")
|
|
@@ -286,29 +283,10 @@ def get_profile_recommendations(profile: UserProfile):
|
|
| 286 |
ids = results.get('ids', [[]])[0]
|
| 287 |
distances = results.get('distances', [[]])[0]
|
| 288 |
|
| 289 |
-
# Convert distances to similarity scores (robust approach)
|
| 290 |
-
if len(distances) == 0:
|
| 291 |
-
return {"recommendations": []}
|
| 292 |
-
|
| 293 |
-
# Normalize scores based on the actual range in results
|
| 294 |
-
min_dist = min(distances)
|
| 295 |
-
max_dist = max(distances)
|
| 296 |
-
|
| 297 |
for i, internship_id in enumerate(ids):
|
| 298 |
-
# DEBUG: Print actual distance values
|
| 299 |
-
print(f"Debug - Internship {internship_id}: distance = {distances[i]}")
|
| 300 |
-
|
| 301 |
-
# Normalize to 0-1 range where smaller distance = higher score
|
| 302 |
-
if max_dist == min_dist:
|
| 303 |
-
# All distances are the same, give them all the same score
|
| 304 |
-
similarity_score = 0.5
|
| 305 |
-
else:
|
| 306 |
-
# Normalize: best match gets 1.0, worst gets 0.0
|
| 307 |
-
similarity_score = 1.0 - ((distances[i] - min_dist) / (max_dist - min_dist))
|
| 308 |
-
|
| 309 |
recommendations.append({
|
| 310 |
"internship_id": internship_id,
|
| 311 |
-
"score":
|
| 312 |
})
|
| 313 |
|
| 314 |
return {"recommendations": recommendations}
|
|
@@ -329,24 +307,10 @@ def search_internships(search: SearchQuery):
|
|
| 329 |
ids = results.get('ids', [[]])[0]
|
| 330 |
distances = results.get('distances', [[]])[0]
|
| 331 |
|
| 332 |
-
# Convert distances to similarity scores (robust approach)
|
| 333 |
-
if len(distances) == 0:
|
| 334 |
-
return {"recommendations": []}
|
| 335 |
-
|
| 336 |
-
# Normalize scores based on the actual range in results
|
| 337 |
-
min_dist = min(distances)
|
| 338 |
-
max_dist = max(distances)
|
| 339 |
-
|
| 340 |
for i, internship_id in enumerate(ids):
|
| 341 |
-
# Normalize to 0-1 range where smaller distance = higher score
|
| 342 |
-
if max_dist == min_dist:
|
| 343 |
-
similarity_score = 0.5
|
| 344 |
-
else:
|
| 345 |
-
similarity_score = 1.0 - ((distances[i] - min_dist) / (max_dist - min_dist))
|
| 346 |
-
|
| 347 |
recommendations.append({
|
| 348 |
"internship_id": internship_id,
|
| 349 |
-
"score":
|
| 350 |
})
|
| 351 |
|
| 352 |
return {"recommendations": recommendations}
|
|
|
|
| 206 |
n_results=random.randint(5, 7) # Match your existing search logic
|
| 207 |
)
|
| 208 |
|
| 209 |
+
# Process results (same as your existing search logic)
|
| 210 |
recommendations = []
|
| 211 |
ids = results.get('ids', [[]])[0]
|
| 212 |
distances = results.get('distances', [[]])[0]
|
| 213 |
|
|
|
|
| 214 |
for i, internship_id in enumerate(ids):
|
|
|
|
|
|
|
| 215 |
recommendations.append({
|
| 216 |
"internship_id": internship_id,
|
| 217 |
+
"score": 1 - distances[i]
|
| 218 |
})
|
| 219 |
|
| 220 |
print(f"✅ Found {len(recommendations)} recommendations for resume")
|
|
|
|
| 283 |
ids = results.get('ids', [[]])[0]
|
| 284 |
distances = results.get('distances', [[]])[0]
|
| 285 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
for i, internship_id in enumerate(ids):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
recommendations.append({
|
| 288 |
"internship_id": internship_id,
|
| 289 |
+
"score": 1 - distances[i]
|
| 290 |
})
|
| 291 |
|
| 292 |
return {"recommendations": recommendations}
|
|
|
|
| 307 |
ids = results.get('ids', [[]])[0]
|
| 308 |
distances = results.get('distances', [[]])[0]
|
| 309 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 310 |
for i, internship_id in enumerate(ids):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 311 |
recommendations.append({
|
| 312 |
"internship_id": internship_id,
|
| 313 |
+
"score": 1 - distances[i]
|
| 314 |
})
|
| 315 |
|
| 316 |
return {"recommendations": recommendations}
|