ak0601 commited on
Commit
276edb7
Β·
verified Β·
1 Parent(s): afa582c

Update src/app_job_copy_1.py

Browse files
Files changed (1) hide show
  1. src/app_job_copy_1.py +32 -24
src/app_job_copy_1.py CHANGED
@@ -378,17 +378,37 @@ def display_job_selection(jobs_df, candidates_df, sh):
378
  st.subheader("Select a job to view potential matches")
379
  job_options = [f"{row['Role']} at {row['Company']}" for _, row in jobs_df.iterrows()]
380
 
381
- if not job_options:
382
- st.warning("No jobs found to display.")
383
- return
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
384
 
385
- # Select job
386
- selected_job_index = st.selectbox("Jobs:", range(len(job_options)),
387
- format_func=lambda x: job_options[x], key="job_selectbox")
388
  job_row = jobs_df.iloc[selected_job_index]
389
  job_row_stack = parse_tech_stack(job_row["Tech Stack"])
390
 
391
- # Display job details
392
  col_job_details_display, _ = st.columns([2, 1])
393
  with col_job_details_display:
394
  st.subheader(f"Job Details: {job_row['Role']}")
@@ -403,13 +423,11 @@ def display_job_selection(jobs_df, candidates_df, sh):
403
  for key, value in job_details_dict.items():
404
  st.markdown(f"**{key}:** {value}")
405
 
406
- # State keys
407
  job_processed_key = f"job_{selected_job_index}_processed_successfully"
408
  job_is_processing_key = f"job_{selected_job_index}_is_currently_processing"
409
  st.session_state.setdefault(job_processed_key, False)
410
  st.session_state.setdefault(job_is_processing_key, False)
411
 
412
- # Check existing sheet data
413
  sheet_name = f"{job_row['Role']} at {job_row['Company']}".strip()[:100]
414
  worksheet_exists = False
415
  existing_candidates_from_sheet = []
@@ -422,7 +440,6 @@ def display_job_selection(jobs_df, candidates_df, sh):
422
  except Exception:
423
  pass
424
 
425
- # Controls
426
  if not st.session_state[job_processed_key] or existing_candidates_from_sheet:
427
  col_find, col_stop = st.columns(2)
428
  with col_find:
@@ -444,7 +461,6 @@ def display_job_selection(jobs_df, candidates_df, sh):
444
  st.warning("Stop request sent. Processing will halt shortly.")
445
  st.rerun()
446
 
447
- # Processing
448
  if st.session_state[job_is_processing_key]:
449
  with st.spinner(f"Processing candidates for {job_row['Role']} at {job_row['Company']}..."):
450
  processed_list = process_candidates_for_job(job_row, candidates_df, st.session_state.llm_chain)
@@ -476,13 +492,12 @@ def display_job_selection(jobs_df, candidates_df, sh):
476
  st.session_state.pop('stop_processing_flag', None)
477
  st.rerun()
478
 
479
- # Display results
480
  should_display = False
481
  final_candidates = []
482
  if not st.session_state[job_is_processing_key]:
483
  if st.session_state[job_processed_key]:
484
  should_display = True
485
- final_candidates = st.session_state.Selected_Candidates[selected_job_index]
486
  elif existing_candidates_from_sheet:
487
  time.sleep(10)
488
  should_display = True
@@ -497,17 +512,14 @@ def display_job_selection(jobs_df, candidates_df, sh):
497
  st.info(f"Displaying: '{sheet_name}'.")
498
 
499
  if should_display:
500
- # Prepare combined text for Copy All
501
- combined_text = ""
502
- for cand in final_candidates:
503
- combined_text += f"Name: {cand.get('Name','N/A')}\nLinkedIn URL: {cand.get('LinkedIn','N/A')}\n\n"
504
-
505
- # Header and Copy All button side by side
506
  col_title, col_copyall = st.columns([3,1])
507
  with col_title:
508
  st.subheader("Selected Candidates")
509
  with col_copyall:
510
- # Use HTML component to reliably include script and button
 
 
 
511
  import json
512
  html = f'''
513
  <button id="copy-all-btn">πŸ“‹ Copy All</button>
@@ -520,12 +532,10 @@ def display_job_selection(jobs_df, candidates_df, sh):
520
  '''
521
  st.components.v1.html(html, height=60)
522
 
523
- # Token usage
524
  if st.session_state.get(job_processed_key) and (
525
  st.session_state.get('total_input_tokens',0) > 0 or st.session_state.get('total_output_tokens',0) > 0):
526
  display_token_usage()
527
 
528
- # List individual candidates
529
  for i, candidate in enumerate(final_candidates):
530
  score = candidate.get('Fit Score',0.0)
531
  score_display = f"{score:.3f}" if isinstance(score,(int,float)) else score
@@ -553,14 +563,12 @@ def display_job_selection(jobs_df, candidates_df, sh):
553
  st.markdown("**Justification:**")
554
  st.info(candidate['justification'])
555
 
556
- # Reset
557
  if st.button("Reset and Process Again", key=f"reset_btn_{selected_job_index}"):
558
  st.session_state[job_processed_key] = False
559
  st.session_state.pop(job_is_processing_key, None)
560
  st.session_state.Selected_Candidates.pop(selected_job_index, None)
561
  st.cache_data.clear()
562
  try: sh.worksheet(sheet_name).clear()
563
-
564
  except: pass
565
  st.rerun()
566
 
 
378
  st.subheader("Select a job to view potential matches")
379
  job_options = [f"{row['Role']} at {row['Company']}" for _, row in jobs_df.iterrows()]
380
 
381
+ if 'last_selected_job_index' not in st.session_state:
382
+ st.session_state.last_selected_job_index = 0
383
+
384
+ selected_job_index = st.selectbox(
385
+ "Jobs:",
386
+ range(len(job_options)),
387
+ format_func=lambda x: job_options[x],
388
+ key="job_selectbox"
389
+ )
390
+
391
+ if selected_job_index != st.session_state.last_selected_job_index:
392
+ old_job_key = st.session_state.last_selected_job_index
393
+ job_processed_key = f"job_{old_job_key}_processed_successfully"
394
+ job_is_processing_key = f"job_{old_job_key}_is_currently_processing"
395
+
396
+ if job_processed_key in st.session_state:
397
+ st.session_state.pop(job_processed_key)
398
+ if job_is_processing_key in st.session_state:
399
+ st.session_state.pop(job_is_processing_key)
400
+
401
+ if 'Selected_Candidates' in st.session_state and old_job_key in st.session_state.Selected_Candidates:
402
+ st.session_state.Selected_Candidates.pop(old_job_key)
403
+
404
+ st.session_state.last_selected_job_index = selected_job_index
405
+ st.session_state.stop_processing_flag = False
406
+ st.cache_data.clear()
407
+ st.rerun()
408
 
 
 
 
409
  job_row = jobs_df.iloc[selected_job_index]
410
  job_row_stack = parse_tech_stack(job_row["Tech Stack"])
411
 
 
412
  col_job_details_display, _ = st.columns([2, 1])
413
  with col_job_details_display:
414
  st.subheader(f"Job Details: {job_row['Role']}")
 
423
  for key, value in job_details_dict.items():
424
  st.markdown(f"**{key}:** {value}")
425
 
 
426
  job_processed_key = f"job_{selected_job_index}_processed_successfully"
427
  job_is_processing_key = f"job_{selected_job_index}_is_currently_processing"
428
  st.session_state.setdefault(job_processed_key, False)
429
  st.session_state.setdefault(job_is_processing_key, False)
430
 
 
431
  sheet_name = f"{job_row['Role']} at {job_row['Company']}".strip()[:100]
432
  worksheet_exists = False
433
  existing_candidates_from_sheet = []
 
440
  except Exception:
441
  pass
442
 
 
443
  if not st.session_state[job_processed_key] or existing_candidates_from_sheet:
444
  col_find, col_stop = st.columns(2)
445
  with col_find:
 
461
  st.warning("Stop request sent. Processing will halt shortly.")
462
  st.rerun()
463
 
 
464
  if st.session_state[job_is_processing_key]:
465
  with st.spinner(f"Processing candidates for {job_row['Role']} at {job_row['Company']}..."):
466
  processed_list = process_candidates_for_job(job_row, candidates_df, st.session_state.llm_chain)
 
492
  st.session_state.pop('stop_processing_flag', None)
493
  st.rerun()
494
 
 
495
  should_display = False
496
  final_candidates = []
497
  if not st.session_state[job_is_processing_key]:
498
  if st.session_state[job_processed_key]:
499
  should_display = True
500
+ final_candidates = st.session_state.Selected_Candidates.get(selected_job_index, [])
501
  elif existing_candidates_from_sheet:
502
  time.sleep(10)
503
  should_display = True
 
512
  st.info(f"Displaying: '{sheet_name}'.")
513
 
514
  if should_display:
 
 
 
 
 
 
515
  col_title, col_copyall = st.columns([3,1])
516
  with col_title:
517
  st.subheader("Selected Candidates")
518
  with col_copyall:
519
+ combined_text = ""
520
+ for cand in final_candidates:
521
+ combined_text += f"Name: {cand.get('Name','N/A')}\nLinkedIn URL: {cand.get('LinkedIn','N/A')}\n\n"
522
+
523
  import json
524
  html = f'''
525
  <button id="copy-all-btn">πŸ“‹ Copy All</button>
 
532
  '''
533
  st.components.v1.html(html, height=60)
534
 
 
535
  if st.session_state.get(job_processed_key) and (
536
  st.session_state.get('total_input_tokens',0) > 0 or st.session_state.get('total_output_tokens',0) > 0):
537
  display_token_usage()
538
 
 
539
  for i, candidate in enumerate(final_candidates):
540
  score = candidate.get('Fit Score',0.0)
541
  score_display = f"{score:.3f}" if isinstance(score,(int,float)) else score
 
563
  st.markdown("**Justification:**")
564
  st.info(candidate['justification'])
565
 
 
566
  if st.button("Reset and Process Again", key=f"reset_btn_{selected_job_index}"):
567
  st.session_state[job_processed_key] = False
568
  st.session_state.pop(job_is_processing_key, None)
569
  st.session_state.Selected_Candidates.pop(selected_job_index, None)
570
  st.cache_data.clear()
571
  try: sh.worksheet(sheet_name).clear()
 
572
  except: pass
573
  st.rerun()
574