""" HRHUB V2.1 - Company View Dynamic company-to-candidate matching interface """ import streamlit as st import sys from pathlib import Path import re # Add parent directory to path for imports parent_dir = Path(__file__).parent.parent sys.path.append(str(parent_dir)) from config import * from data.data_loader import ( load_embeddings, # find_top_matches_company # Function doesn't exist yet - using embedded version below ) from utils.display import ( display_company_profile_basic, display_candidate_card_basic, display_match_table_candidates, display_stats_overview_company ) from utils.visualization import create_network_graph from utils.viz_heatmap import render_skills_heatmap_section from utils.viz_bilateral import render_bilateral_fairness_section # NEW IMPORT import streamlit.components.v1 as components import numpy as np def configure_page(): """Configure Streamlit page settings and custom CSS.""" st.set_page_config( page_title="HRHUB - Company View", page_icon="π’", layout="wide", initial_sidebar_state="expanded" ) # Custom CSS st.markdown(""" """, unsafe_allow_html=True) def validate_company_input(input_str): """ Validate company input (ID or search term). Returns: (is_valid, company_id, error_message) """ if not input_str: return False, None, "Please enter a company ID or name" input_clean = input_str.strip() # Check if it's a numeric ID if input_clean.isdigit(): company_id = int(input_clean) return True, company_id, None # Otherwise treat as search term (we'll search by name) return True, input_clean, None def find_company_by_name(companies_df, search_term): """ Find company by name (case-insensitive partial match). Returns: (found, company_id, company_name) """ search_lower = search_term.lower() # Search in company names if 'name' in companies_df.columns: matches = companies_df[companies_df['name'].str.lower().str.contains(search_lower, na=False)] if len(matches) > 0: # Return first match company_id = matches.index[0] company_name = matches.iloc[0]['name'] return True, company_id, company_name return False, None, None def find_top_candidate_matches(company_id, company_embeddings, candidate_embeddings, candidates_df, top_k=10): """ Find top candidate matches for a company (reverse of candidate matching). """ # Get company embedding company_emb = company_embeddings[company_id].reshape(1, -1) # Calculate cosine similarity with all candidates # Normalize embeddings company_norm = company_emb / np.linalg.norm(company_emb) candidate_norms = candidate_embeddings / np.linalg.norm(candidate_embeddings, axis=1, keepdims=True) # Compute similarities similarities = np.dot(candidate_norms, company_norm.T).flatten() # Get top K indices top_indices = np.argsort(similarities)[::-1][:top_k] # Format results matches = [] for idx in top_indices: matches.append({ 'candidate_id': int(idx), 'score': float(similarities[idx]) }) return matches def render_sidebar(): """Render sidebar with controls and information.""" with st.sidebar: # Logo/Title st.markdown("### π’ Company Matching") st.markdown("---") # Settings section st.markdown("### βοΈ Settings") # Number of matches top_k = st.slider( "Number of Matches", min_value=5, max_value=20, value=DEFAULT_TOP_K, step=5, help="Select how many top candidates to display" ) # Minimum score threshold min_score = st.slider( "Minimum Match Score", min_value=0.0, max_value=1.0, value=MIN_SIMILARITY_SCORE, step=0.05, help="Filter candidates below this similarity score" ) st.markdown("---") # View mode selection st.markdown("### π View Mode") view_mode = st.radio( "Select view:", ["π Overview", "π Detailed Cards", "π Table View"], help="Choose how to display candidate matches" ) st.markdown("---") # Information section with st.expander("βΉοΈ About", expanded=False): st.markdown(""" **Company View** helps you discover top talent based on: - π€ **NLP Embeddings**: 384-dimensional semantic space - π **Cosine Similarity**: Scale-invariant matching - π **Job Postings Bridge**: Vocabulary alignment **How it works:** 1. Enter company ID or search by name 2. System finds top candidate matches 3. Explore candidates with scores and skills 4. Visualize talent network via graph """) with st.expander("π Input Format", expanded=False): st.markdown(""" **Valid formats:** - `9418` β Company ID 9418 - `30989` β Company ID 30989 - `Anblicks` β Search by name - `iO Associates` β Partial name search **Search tips:** - Case-insensitive - Partial matches work - Returns first match found """) with st.expander("π Coverage Info", expanded=False): st.markdown(""" **Company Coverage:** - π’ **30,000 companies** with job postings - π‘ **120,000 companies** via collaborative filtering - π **5x coverage expansion** through skill inference Companies without job postings inherit skills from similar companies. """) st.markdown("---") # Back to home button if st.button("π Back to Home", use_container_width=True): st.switch_page("app.py") # Version info st.caption(f"Version: {VERSION}") st.caption("Β© 2024 HRHUB Team") return top_k, min_score, view_mode def get_network_graph_data_company(company_id, matches, companies_df): """Generate network graph data from matches (company perspective).""" nodes = [] edges = [] # Add company node (red/orange) company_name = companies_df.iloc[company_id].get('name', f'Company {company_id}') if len(company_name) > 30: company_name = company_name[:27] + '...' nodes.append({ 'id': f'COMP{company_id}', 'label': company_name, 'color': '#ff6b6b', 'shape': 'box', 'size': 30 }) # Add candidate nodes (green) and edges for cand_id, score, cand_data in matches: nodes.append({ 'id': f'C{cand_id}', 'label': f'Candidate #{cand_id}', 'color': '#4ade80', 'shape': 'dot', 'size': 20 }) edges.append({ 'from': f'COMP{company_id}', 'to': f'C{cand_id}', 'value': float(score) * 10, 'title': f'Match Score: {score:.3f}' }) return {'nodes': nodes, 'edges': edges} def render_network_section(company_id: int, matches, companies_df): """Render interactive network visualization section.""" st.markdown('
Discover top talent for your company
', unsafe_allow_html=True) # Render sidebar and get settings top_k, min_score, view_mode = render_sidebar() st.markdown("---") # Load embeddings (cache in session state) if 'embeddings_loaded' not in st.session_state: with st.spinner("π Loading embeddings and data..."): try: cand_emb, comp_emb, cand_df, comp_df = load_embeddings() st.session_state.embeddings_loaded = True st.session_state.candidate_embeddings = cand_emb st.session_state.company_embeddings = comp_emb st.session_state.candidates_df = cand_df st.session_state.companies_df = comp_df st.markdown("""