ak0601 commited on
Commit
ec2993d
·
verified ·
1 Parent(s): 0abf4be

Update src/app_job_copy_1.py

Browse files
Files changed (1) hide show
  1. src/app_job_copy_1.py +0 -199
src/app_job_copy_1.py CHANGED
@@ -377,205 +377,6 @@ def main():
377
  st.error(f"Error processing files or data: {e}")
378
  st.divider()
379
 
380
- # def display_job_selection(jobs_df, candidates_df, sh):
381
- # st.subheader("Select a job to view potential matches")
382
- # job_options = [f"{row['Role']} at {row['Company']}" for _, row in jobs_df.iterrows()]
383
-
384
- # if 'last_selected_job_index' not in st.session_state:
385
- # st.session_state.last_selected_job_index = 0
386
-
387
- # selected_job_index = st.selectbox(
388
- # "Jobs:",
389
- # range(len(job_options)),
390
- # format_func=lambda x: job_options[x],
391
- # key="job_selectbox"
392
- # )
393
-
394
- # if selected_job_index != st.session_state.last_selected_job_index:
395
- # old_job_key = st.session_state.last_selected_job_index
396
- # job_processed_key = f"job_{old_job_key}_processed_successfully"
397
- # job_is_processing_key = f"job_{old_job_key}_is_currently_processing"
398
-
399
- # if job_processed_key in st.session_state:
400
- # st.session_state.pop(job_processed_key)
401
- # if job_is_processing_key in st.session_state:
402
- # st.session_state.pop(job_is_processing_key)
403
-
404
- # if 'Selected_Candidates' in st.session_state and old_job_key in st.session_state.Selected_Candidates:
405
- # st.session_state.Selected_Candidates.pop(old_job_key)
406
-
407
- # st.session_state.last_selected_job_index = selected_job_index
408
- # st.session_state.stop_processing_flag = False
409
- # st.cache_data.clear()
410
- # st.rerun()
411
-
412
- # job_row = jobs_df.iloc[selected_job_index]
413
- # job_row_stack = parse_tech_stack(job_row["Tech Stack"])
414
-
415
- # col_job_details_display, _ = st.columns([2, 1])
416
- # with col_job_details_display:
417
- # st.subheader(f"Job Details: {job_row['Role']}")
418
- # job_details_dict = {
419
- # "Company": job_row["Company"],
420
- # "Role": job_row["Role"],
421
- # "Description": job_row.get("One liner", "N/A"),
422
- # "Locations": job_row.get("Locations", "N/A"),
423
- # "Industry": job_row.get("Industry", "N/A"),
424
- # "Tech Stack": display_tech_stack(job_row_stack)
425
- # }
426
- # for key, value in job_details_dict.items():
427
- # st.markdown(f"**{key}:** {value}")
428
-
429
- # job_processed_key = f"job_{selected_job_index}_processed_successfully"
430
- # job_is_processing_key = f"job_{selected_job_index}_is_currently_processing"
431
- # st.session_state.setdefault(job_processed_key, False)
432
- # st.session_state.setdefault(job_is_processing_key, False)
433
-
434
- # sheet_name = f"{job_row['Role']} at {job_row['Company']}".strip()[:100]
435
- # worksheet_exists = False
436
- # existing_candidates_from_sheet = []
437
- # try:
438
- # cand_ws = sh.worksheet(sheet_name)
439
- # worksheet_exists = True
440
- # data = cand_ws.get_all_values()
441
- # if len(data) > 1:
442
- # existing_candidates_from_sheet = data
443
- # except Exception:
444
- # pass
445
-
446
- # if not st.session_state[job_processed_key] or existing_candidates_from_sheet:
447
- # col_find, col_stop = st.columns(2)
448
- # with col_find:
449
- # if st.button("Find Matching Candidates for this Job", key=f"find_btn_{selected_job_index}",
450
- # disabled=st.session_state[job_is_processing_key]):
451
- # if not os.environ.get("OPENAI_API_KEY") or st.session_state.llm_chain is None:
452
- # st.error("OpenAI API key not set or LLM not initialized.")
453
- # else:
454
- # st.session_state[job_is_processing_key] = True
455
- # st.session_state.stop_processing_flag = False
456
- # st.session_state.Selected_Candidates[selected_job_index] = []
457
- # st.session_state[job_processed_key] = False
458
- # st.rerun()
459
- # with col_stop:
460
- # if st.session_state[job_is_processing_key]:
461
- # if st.button("STOP Processing", key=f"stop_btn_{selected_job_index}"):
462
- # st.session_state.stop_processing_flag = True
463
- # st.cache_data.clear()
464
- # st.warning("Stop request sent. Processing will halt shortly.")
465
- # st.rerun()
466
-
467
- # if st.session_state[job_is_processing_key]:
468
- # with st.spinner(f"Processing candidates for {job_row['Role']} at {job_row['Company']}..."):
469
- # processed_list = process_candidates_for_job(job_row, candidates_df, st.session_state.llm_chain)
470
- # st.session_state[job_is_processing_key] = False
471
-
472
- # if not st.session_state.get('stop_processing_flag', False):
473
- # if processed_list:
474
- # processed_list.sort(key=lambda x: x.get("Fit Score", 0.0), reverse=True)
475
- # st.session_state.Selected_Candidates[selected_job_index] = processed_list
476
- # st.session_state[job_processed_key] = True
477
- # try:
478
- # target_ws = sh.worksheet(sheet_name) if worksheet_exists else sh.add_worksheet(
479
- # title=sheet_name, rows=max(100, len(processed_list)+10), cols=20)
480
- # headers = list(processed_list[0].keys())
481
- # rows = [headers] + [[str(c.get(h, "")) for h in headers] for c in processed_list]
482
- # target_ws.clear()
483
- # target_ws.update('A1', rows)
484
- # st.success(f"Results saved to Google Sheet: '{sheet_name}'")
485
- # except Exception as e:
486
- # st.error(f"Error writing to Google Sheet '{sheet_name}': {e}")
487
- # else:
488
- # st.info("No suitable candidates found after processing.")
489
- # st.session_state.Selected_Candidates[selected_job_index] = []
490
- # st.session_state[job_processed_key] = True
491
- # else:
492
- # st.info("Processing was stopped by user.")
493
- # st.session_state[job_processed_key] = False
494
- # st.session_state.Selected_Candidates[selected_job_index] = []
495
- # st.session_state.pop('stop_processing_flag', None)
496
- # st.rerun()
497
-
498
- # should_display = False
499
- # final_candidates = []
500
- # if not st.session_state[job_is_processing_key]:
501
- # if st.session_state[job_processed_key]:
502
- # should_display = True
503
- # final_candidates = st.session_state.Selected_Candidates.get(selected_job_index, [])
504
- # elif existing_candidates_from_sheet:
505
- # should_display = True
506
- # headers = existing_candidates_from_sheet[0]
507
- # for row in existing_candidates_from_sheet[1:]:
508
- # cand = {headers[i]: row[i] if i < len(row) else None for i in range(len(headers))}
509
- # try: cand['Fit Score'] = float(cand.get('Fit Score',0))
510
- # except: cand['Fit Score'] = 0.0
511
- # final_candidates.append(cand)
512
- # final_candidates.sort(key=lambda x: x.get('Fit Score',0.0), reverse=True)
513
-
514
- # if not st.session_state[job_processed_key]:
515
- # st.info(f"Displaying: '{sheet_name}'.")
516
- # time.sleep(10)
517
-
518
- # if should_display:
519
- # col_title, col_copyall = st.columns([3,1])
520
- # with col_title:
521
- # st.subheader("Selected Candidates")
522
- # with col_copyall:
523
- # combined_text = ""
524
- # for cand in final_candidates:
525
- # combined_text += f"Name: {cand.get('Name','N/A')}\nLinkedIn URL: {cand.get('LinkedIn','N/A')}\n\n"
526
-
527
- # import json
528
- # html = f'''
529
- # <button id="copy-all-btn">📋 Copy All</button>
530
- # <script>
531
- # const combinedText = {json.dumps(combined_text)};
532
- # document.getElementById("copy-all-btn").onclick = () => {{
533
- # navigator.clipboard.writeText(combinedText);
534
- # }};
535
- # </script>
536
- # '''
537
- # st.components.v1.html(html, height=60)
538
-
539
- # if st.session_state.get(job_processed_key) and (
540
- # st.session_state.get('total_input_tokens',0) > 0 or st.session_state.get('total_output_tokens',0) > 0):
541
- # display_token_usage()
542
-
543
- # for i, candidate in enumerate(final_candidates):
544
- # score = candidate.get('Fit Score',0.0)
545
- # score_display = f"{score:.3f}" if isinstance(score,(int,float)) else score
546
- # exp_title = f"{i+1}. {candidate.get('Name','N/A')} (Score: {score_display})"
547
- # with st.expander(exp_title):
548
- # text_copy = f"Candidate: {candidate.get('Name','N/A')}\nLinkedIn: {candidate.get('LinkedIn','N/A')}\n"
549
- # btn = f"copy_btn_job{selected_job_index}_cand{i}"
550
- # js = f'''
551
- # <script>
552
- # function copyToClipboard_{btn}() {{ navigator.clipboard.writeText(`{text_copy}`); }}
553
- # </script>
554
- # <button onclick="copyToClipboard_{btn}()">📋 Copy Details</button>
555
- # '''
556
- # cols = st.columns([0.82,0.18])
557
- # with cols[1]: st.components.v1.html(js, height=40)
558
- # with cols[0]:
559
- # st.markdown(f"**Summary:** {candidate.get('summary','N/A')}")
560
- # st.markdown(f"**Current:** {candidate.get('Current Title & Company','N/A')}")
561
- # st.markdown(f"**Education:** {candidate.get('Educational Background','N/A')}")
562
- # st.markdown(f"**Experience:** {candidate.get('Years of Experience','N/A')}")
563
- # st.markdown(f"**Location:** {candidate.get('Location','N/A')}")
564
- # if candidate.get('LinkedIn'):
565
- # st.markdown(f"**[LinkedIn Profile]({candidate['LinkedIn']})**")
566
- # if candidate.get('justification'):
567
- # st.markdown("**Justification:**")
568
- # st.info(candidate['justification'])
569
-
570
- # if st.button("Reset and Process Again", key=f"reset_btn_{selected_job_index}"):
571
- # st.session_state[job_processed_key] = False
572
- # st.session_state.pop(job_is_processing_key, None)
573
- # st.session_state.Selected_Candidates.pop(selected_job_index, None)
574
- # st.cache_data.clear()
575
- # try: sh.worksheet(sheet_name).clear()
576
- # except: pass
577
- # st.rerun()
578
-
579
  def display_job_selection(jobs_df, candidates_df, sh):
580
  st.subheader("Select a job to view potential matches")
581
  job_options = [f"{row['Role']} at {row['Company']}" for _, row in jobs_df.iterrows()]
 
377
  st.error(f"Error processing files or data: {e}")
378
  st.divider()
379
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
380
  def display_job_selection(jobs_df, candidates_df, sh):
381
  st.subheader("Select a job to view potential matches")
382
  job_options = [f"{row['Role']} at {row['Company']}" for _, row in jobs_df.iterrows()]