Spaces:
Build error
Build error
Update with rerank score
Browse files
app.py
CHANGED
|
@@ -293,6 +293,11 @@ def check_keywords_in_content(database_path, table_name, input_id, keywords):
|
|
| 293 |
|
| 294 |
return contains_keywords
|
| 295 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
def load_candidates(fillup):
|
| 297 |
with st.spinner("Load the candidates, this may take a moment..."):
|
| 298 |
# print(st.session_state["job_string"])
|
|
@@ -320,16 +325,36 @@ def load_candidates(fillup):
|
|
| 320 |
# print(filter_string)
|
| 321 |
if not fillup:
|
| 322 |
while len(checked_candidates) < target_candidates_count:
|
| 323 |
-
# Führe eine similarity search durch und erhalte 100 Kandidaten
|
| 324 |
-
if st.session_state["search_type"]:
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 329 |
print("similarity")
|
| 330 |
# raw_candidates = st.session_state["db"].similarity_search(query_string, k=candidates_per_search+current_offset, filters=filter_string)
|
| 331 |
raw_candidates = st.session_state["db"].similarity_search_with_relevance_scores(query_string, k=candidates_per_search+current_offset, filters=filter_string)
|
| 332 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
for candidate in raw_candidates[current_offset:]:
|
| 334 |
candidates_id = candidate[0].metadata["source"].split("/")[-1]
|
| 335 |
keyword_bool = check_keywords_in_content(db_path, table_name, candidates_id, text_area_params.split(','))
|
|
@@ -358,14 +383,26 @@ def load_candidates(fillup):
|
|
| 358 |
# Solange die Anzahl der überprüften Kandidaten kleiner als die Zielanzahl ist
|
| 359 |
while len(st.session_state["docs_res"]) < target_candidates_count:
|
| 360 |
# Führe eine similarity search durch und erhalte 100 Kandidaten
|
| 361 |
-
if st.session_state["
|
| 362 |
-
print("hybrid")
|
| 363 |
-
# raw_candidates = st.session_state["db"].hybrid_search(query_string, k=candidates_per_search+current_offset, filters=filter_string)
|
| 364 |
-
raw_candidates = st.session_state["db"].hybrid_search_with_score(query_string, k=candidates_per_search+current_offset, filters=filter_string)
|
| 365 |
-
else:
|
| 366 |
print("similarity")
|
| 367 |
# raw_candidates = st.session_state["db"].similarity_search(query_string, k=candidates_per_search+current_offset, filters=filter_string)
|
| 368 |
raw_candidates = st.session_state["db"].similarity_search_with_relevance_scores(query_string, k=candidates_per_search+current_offset, filters=filter_string)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 369 |
temp_offset_add = 0
|
| 370 |
for candidate in raw_candidates[current_offset:]:
|
| 371 |
candidates_id = candidate[0].metadata["source"].split("/")[-1]
|
|
@@ -425,13 +462,14 @@ col1.title("Candidate Search")
|
|
| 425 |
col2.image("https://www.workgenius.com/wp-content/uploads/2023/03/WorkGenius_navy-1.svg")
|
| 426 |
|
| 427 |
st.write("Please upload the job description for which you would like candidates to be proposed.")
|
| 428 |
-
|
|
|
|
| 429 |
|
| 430 |
-
with col_file:
|
| 431 |
-
|
| 432 |
-
with col_clear:
|
| 433 |
-
|
| 434 |
-
|
| 435 |
|
| 436 |
if st.session_state["job"]:
|
| 437 |
if not st.session_state["job_string"]:
|
|
@@ -470,8 +508,10 @@ if st.session_state["job"]:
|
|
| 470 |
st.session_state["job_string"] = st.session_state["optimized_job_edited"]
|
| 471 |
st.rerun()
|
| 472 |
|
| 473 |
-
st.write("Switch from a similarity search (default) to a hybrid search (activated)")
|
| 474 |
-
st.toggle("Switch Search", key="search_type")
|
|
|
|
|
|
|
| 475 |
|
| 476 |
st.write("Activate the following toggles to filter according to the respective properties:")
|
| 477 |
col_screening, col_handoff, col_placed = st.columns([1,1,1])
|
|
@@ -514,8 +554,15 @@ if (st.session_state["job_string"] and submit) or st.session_state["docs_res"]:
|
|
| 514 |
st.rerun()
|
| 515 |
with cols_final[0]:
|
| 516 |
# st.subheader(doc.metadata["source"])
|
| 517 |
-
|
| 518 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 519 |
if len(st.session_state["docs_res"])>=10:
|
| 520 |
if st.button("Accept candidates", key="accept_candidates_btn"):
|
| 521 |
print("hello")
|
|
@@ -698,7 +745,7 @@ Your Candidate-Search-Tool
|
|
| 698 |
try:
|
| 699 |
bullets = generate_job_bullets(st.session_state["job_string"])
|
| 700 |
client = Client(os.getenv("TWILIO_SID"), os.getenv("TWILIO_API"))
|
| 701 |
-
message_body = f"Dear candidate,\n\nare you interested in the following position: \n
|
| 702 |
message = client.messages.create(
|
| 703 |
to=st.session_state["recruiter_phone"],
|
| 704 |
from_="+1 857 214 8753",
|
|
|
|
| 293 |
|
| 294 |
return contains_keywords
|
| 295 |
|
| 296 |
+
def clear_temp_candidates():
|
| 297 |
+
if not st.session_state["final_candidates"]:
|
| 298 |
+
print("i am cleared")
|
| 299 |
+
st.session_state["docs_res"] = []
|
| 300 |
+
|
| 301 |
def load_candidates(fillup):
|
| 302 |
with st.spinner("Load the candidates, this may take a moment..."):
|
| 303 |
# print(st.session_state["job_string"])
|
|
|
|
| 325 |
# print(filter_string)
|
| 326 |
if not fillup:
|
| 327 |
while len(checked_candidates) < target_candidates_count:
|
| 328 |
+
# # Führe eine similarity search durch und erhalte 100 Kandidaten
|
| 329 |
+
# if st.session_state["search_type"]:
|
| 330 |
+
# print("hybrid")
|
| 331 |
+
# # raw_candidates = st.session_state["db"].hybrid_search(query_string, k=candidates_per_search+current_offset, filters=filter_string)
|
| 332 |
+
# raw_candidates = st.session_state["db"].hybrid_search_with_score(query_string, k=candidates_per_search+current_offset, filters=filter_string)
|
| 333 |
+
# else:
|
| 334 |
+
# print("similarity")
|
| 335 |
+
# # raw_candidates = st.session_state["db"].similarity_search(query_string, k=candidates_per_search+current_offset, filters=filter_string)
|
| 336 |
+
# raw_candidates = st.session_state["db"].similarity_search_with_relevance_scores(query_string, k=candidates_per_search+current_offset, filters=filter_string)
|
| 337 |
+
#"Similarity", "Hybrid", "Semantic ranking"
|
| 338 |
+
if st.session_state["search_radio"] == "Similarity":
|
| 339 |
print("similarity")
|
| 340 |
# raw_candidates = st.session_state["db"].similarity_search(query_string, k=candidates_per_search+current_offset, filters=filter_string)
|
| 341 |
raw_candidates = st.session_state["db"].similarity_search_with_relevance_scores(query_string, k=candidates_per_search+current_offset, filters=filter_string)
|
| 342 |
+
elif st.session_state["search_radio"] == "Hybrid":
|
| 343 |
+
print("hybrid")
|
| 344 |
+
# raw_candidates = st.session_state["db"].hybrid_search(query_string, k=candidates_per_search+current_offset, filters=filter_string)
|
| 345 |
+
raw_candidates = st.session_state["db"].hybrid_search_with_score(query_string, k=candidates_per_search+current_offset, filters=filter_string)
|
| 346 |
+
elif st.session_state["search_radio"] == "Semantic ranking":
|
| 347 |
+
print("Semantic ranking")
|
| 348 |
+
print("Filter string"+filter_string)
|
| 349 |
+
print("query"+query_string)
|
| 350 |
+
print("offset: "+str(candidates_per_search+current_offset))
|
| 351 |
+
# raw_candidates = st.session_state["db"].hybrid_search(query_string, k=candidates_per_search+current_offset, filters=filter_string)
|
| 352 |
+
try:
|
| 353 |
+
raw_candidates = st.session_state["db"].semantic_hybrid_search_with_score_and_rerank(query_string, k=50, filters=filter_string)
|
| 354 |
+
except Exception as e:
|
| 355 |
+
print(f"Fehler beim laden der Kandidaten: {str(e)}")
|
| 356 |
+
raw_candidates = []
|
| 357 |
+
st.warning("Something went wrong. Please press 'Search candidates' again or reload the page.")
|
| 358 |
for candidate in raw_candidates[current_offset:]:
|
| 359 |
candidates_id = candidate[0].metadata["source"].split("/")[-1]
|
| 360 |
keyword_bool = check_keywords_in_content(db_path, table_name, candidates_id, text_area_params.split(','))
|
|
|
|
| 383 |
# Solange die Anzahl der überprüften Kandidaten kleiner als die Zielanzahl ist
|
| 384 |
while len(st.session_state["docs_res"]) < target_candidates_count:
|
| 385 |
# Führe eine similarity search durch und erhalte 100 Kandidaten
|
| 386 |
+
if st.session_state["search_radio"] == "Similarity":
|
|
|
|
|
|
|
|
|
|
|
|
|
| 387 |
print("similarity")
|
| 388 |
# raw_candidates = st.session_state["db"].similarity_search(query_string, k=candidates_per_search+current_offset, filters=filter_string)
|
| 389 |
raw_candidates = st.session_state["db"].similarity_search_with_relevance_scores(query_string, k=candidates_per_search+current_offset, filters=filter_string)
|
| 390 |
+
elif st.session_state["search_radio"] == "Hybrid":
|
| 391 |
+
print("hybrid")
|
| 392 |
+
# raw_candidates = st.session_state["db"].hybrid_search(query_string, k=candidates_per_search+current_offset, filters=filter_string)
|
| 393 |
+
raw_candidates = st.session_state["db"].hybrid_search_with_score(query_string, k=candidates_per_search+current_offset, filters=filter_string)
|
| 394 |
+
elif st.session_state["search_radio"] == "Semantic ranking":
|
| 395 |
+
print("Semantic ranking")
|
| 396 |
+
print("Filter string"+filter_string)
|
| 397 |
+
print("query"+query_string)
|
| 398 |
+
print("offset: "+str(candidates_per_search+current_offset))
|
| 399 |
+
# raw_candidates = st.session_state["db"].hybrid_search(query_string, k=candidates_per_search+current_offset, filters=filter_string)
|
| 400 |
+
try:
|
| 401 |
+
raw_candidates = st.session_state["db"].semantic_hybrid_search_with_score_and_rerank(query_string, k=50, filters=filter_string)
|
| 402 |
+
except Exception as e:
|
| 403 |
+
print(f"Fehler beim laden der Kandidaten: {str(e)}")
|
| 404 |
+
raw_candidates = []
|
| 405 |
+
st.warning("Something went wrong. Please press 'Search candidates' again or reload the page.")
|
| 406 |
temp_offset_add = 0
|
| 407 |
for candidate in raw_candidates[current_offset:]:
|
| 408 |
candidates_id = candidate[0].metadata["source"].split("/")[-1]
|
|
|
|
| 462 |
col2.image("https://www.workgenius.com/wp-content/uploads/2023/03/WorkGenius_navy-1.svg")
|
| 463 |
|
| 464 |
st.write("Please upload the job description for which you would like candidates to be proposed.")
|
| 465 |
+
uploaded_file_jobdescription = st.file_uploader("Upload the job description:", type=["pdf"], key="job")
|
| 466 |
+
# col_file, col_clear = st.columns([6,1])
|
| 467 |
|
| 468 |
+
# with col_file:
|
| 469 |
+
# uploaded_file_jobdescription = st.file_uploader("Upload the job description:", type=["pdf"], key="job")
|
| 470 |
+
# with col_clear:
|
| 471 |
+
# if st.button("Clear", use_container_width=True):
|
| 472 |
+
# streamlit_js_eval(js_expressions="parent.window.location.reload()")
|
| 473 |
|
| 474 |
if st.session_state["job"]:
|
| 475 |
if not st.session_state["job_string"]:
|
|
|
|
| 508 |
st.session_state["job_string"] = st.session_state["optimized_job_edited"]
|
| 509 |
st.rerun()
|
| 510 |
|
| 511 |
+
# st.write("Switch from a similarity search (default) to a hybrid search (activated)")
|
| 512 |
+
# st.toggle("Switch Search", key="search_type")
|
| 513 |
+
|
| 514 |
+
st.radio("Select a search variant",options=["Similarity", "Hybrid", "Semantic ranking"], key="search_radio",on_change=clear_temp_candidates)
|
| 515 |
|
| 516 |
st.write("Activate the following toggles to filter according to the respective properties:")
|
| 517 |
col_screening, col_handoff, col_placed = st.columns([1,1,1])
|
|
|
|
| 554 |
st.rerun()
|
| 555 |
with cols_final[0]:
|
| 556 |
# st.subheader(doc.metadata["source"])
|
| 557 |
+
if st.session_state["search_radio"] == "Similarity":
|
| 558 |
+
with st.expander(doc[0].metadata["name"]+" with a similarity percentage of: "+str(round(doc[1] * 100, 3))+ "%"):
|
| 559 |
+
st.write(doc[0].page_content)
|
| 560 |
+
elif st.session_state["search_radio"] == "Hybrid":
|
| 561 |
+
with st.expander(doc[0].metadata["name"]+" with a hybrid search score of: "+str(round(doc[1] * 100, 3))):
|
| 562 |
+
st.write(doc[0].page_content)
|
| 563 |
+
elif st.session_state["search_radio"] == "Semantic ranking":
|
| 564 |
+
with st.expander(doc[0].metadata["name"]+" with a rerank score of: "+str(round(doc[2] * 100, 3))):
|
| 565 |
+
st.write(doc[0].page_content)
|
| 566 |
if len(st.session_state["docs_res"])>=10:
|
| 567 |
if st.button("Accept candidates", key="accept_candidates_btn"):
|
| 568 |
print("hello")
|
|
|
|
| 745 |
try:
|
| 746 |
bullets = generate_job_bullets(st.session_state["job_string"])
|
| 747 |
client = Client(os.getenv("TWILIO_SID"), os.getenv("TWILIO_API"))
|
| 748 |
+
message_body = f"Dear candidate,\n\nare you interested in the following position: \n"+st.session_state["job_title"]+"\n\n"+bullets+"\n\nThen please answer with 'yes'\n\nSincerely,\n"+"WorkGenius"
|
| 749 |
message = client.messages.create(
|
| 750 |
to=st.session_state["recruiter_phone"],
|
| 751 |
from_="+1 857 214 8753",
|