Spaces:
Sleeping
Sleeping
Update app.py
Browse files9 unmodified lines1011121314151617181920181920212223212223242526272829252627282930313231323334353637383933343541424344363738394041424346474445495046474849100 unmodified lines1501511521531541551561571581591601611621631 unmodified line16516616716416516616716816917017116816917024 unmodified lines1951961972021981992002012022072032042052063 unmodified lines2102112122172182192132142152162172182192202212222232242252262272252282292302311 unmodified line2332342352332342352362372382392402412362372382392402412422432442452462472482492502512432442452462522532542559 unmodified lines if pd.isna(salary_str): return 0 # Debug print st.write(f"Processing salary string: {salary_str}") salary_str = str(salary_str).lower().replace(',', '') # Convert hourly rate to annual salary (assuming 40 hours/week, 52 weeks/year) HOURS_PER_YEAR = 40 * 52 # 2080 hours per year # Handle hourly rates with ranges (e.g., "50-54 an hour" or "$50-$54/hr") hourly_range_match = re.search(r'(\d+\.?\d*)\s*[-to]+\s*(\d+\.?\d*)\s*(?:an hour|per hour|\/hour|\/hr|\$?\/h|\$?ph|hr)', salary_str) if hourly_range_match: low, high = map(float, hourly_range_match.groups()) avg_hourly = (low + high) / 2 return int(avg_hourly * HOURS_PER_YEAR) # First, clean up special characters and standardize format # Convert em-dashes and other dash-like characters to regular hyphens salary_str = salary_str.replace('−', '-').replace('–', '-') # Remove duplicate hyphens salary_str = re.sub(r'-+', '-', salary_str) # Debug print after cleaning st.write(f"Cleaned salary string: {salary_str}") # Handle single hourly rate (e.g., "50 an hour" or "$50/hr") hourly_match = re.search(r'(\d+\.?\d*)\s*(?:an hour|per hour|\/hour|\/hr|\$?\/h|\$?ph|hr)', salary_str) if hourly_match: hourly_rate = float(hourly_match.group(1)) return int(hourly_rate * HOURS_PER_YEAR) # Extract all numbers from the string numbers = [float(num) for num in re.findall(r'\d+\.?\d*', salary_str)] # Handle ranges for annual salary (e.g., "150000-200000" or "150k-200k") range_match = re.search(r'(\d+\.?\d*)\s*k?\s*[-to]+\s*(\d+\.?\d*)\s*k?', salary_str) if range_match: low, high = map(float, range_match.groups()) # Convert if 'k' is in the string if 'k' in salary_str: low *= 1000 high *= 1000 return int((low + high) // 2) # Debug print numbers found st.write(f"Found numbers: {numbers}") # Handle single values with 'k' (e.g., "150k" or "150K") k_match = re.search(r'(\d+\.?\d*)\s*k', salary_str) if k_match: return int(float(k_match.group(1)) * 1000) if len(numbers) >= 2: min_salary = min(numbers) max_salary = max(numbers) if min_salary < max_salary: # Only use as range if numbers are different average = (min_salary + max_salary) / 2 st.write(f"Calculated average: {average}") return int(average) # Extract plain numbers numbers = re.findall(r'\d+\.?\d*', salary_str) # If we haven't returned by now, process as single number if numbers: # Take the first number found salary = float(numbers[0]) salary = max(numbers) # Use the largest number found # If the number is small (likely in thousands), multiply by 1000 if salary < 1000: salary *= 1000100 unmodified lines st.title("Job Search Application") st.write("Find jobs that match your preferences!")
# Initialize session state for expanded descriptions if 'expanded_descriptions' not in st.session_state: st.session_state.expanded_descriptions = {} if 'search_performed' not in st.session_state: st.session_state.search_performed = False if 'filtered_jobs' not in st.session_state: st.session_state.filtered_jobs = pd.DataFrame()
# Load data url = "https://huggingface.co/datasets/burcuonel/datajob_indeed_usa/raw/main/datajob_indeed_usa.csv" jobs_df = load_and_preprocess_data(url)1 unmodified line if jobs_df is None: return
# Initialize session state if 'search_performed' not in st.session_state: st.session_state.search_performed = False if 'filtered_jobs' not in st.session_state: st.session_state.filtered_jobs = pd.DataFrame() if 'expanded_descriptions' not in st.session_state: st.session_state.expanded_descriptions = set()
# Sidebar filters with st.sidebar: st.header("Search Filters")24 unmodified lines ) st.session_state.search_performed = True # Reset expanded descriptions when new search is performed st.session_state.expanded_descriptions = set() st.session_state.expanded_descriptions = {}
if st.button("Reset Filters", use_container_width=True): st.session_state.search_performed = False st.session_state.filtered_jobs = pd.DataFrame() st.session_state.expanded_descriptions = set() st.session_state.expanded_descriptions = {} st.rerun()
# Display results3 unmodified lines
if not filtered_jobs.empty: for index, row in filtered_jobs.iterrows(): with st.expander(f"{row['Title']} - {row['Location']}"): st.write(f"**Salary:** {row['Salary']}") st.write(f"**Cleaned Salary:** {row['clean_salary']}") job_key = f"job_{index}" with st.expander(f"{row['Title']} - {row['Location']}", expanded=True): col1, col2 = st.columns(2) with col1: st.write(f"**Salary:** {row['Salary']}") with col2: st.write(f"**Cleaned Salary:** ${row['clean_salary']:,}") if 'cluster' in row: st.write(f"**Cluster:** {row['cluster']}") st.write("**Description:**") description = row['Description']
# Highlight keywords # Highlight keywords if any if keywords: keyword_list = [k.strip() for k in keywords.split(',')] for keyword in keyword_list:1 unmodified line pattern = re.compile(f'({re.escape(keyword)})', re.IGNORECASE) description = pattern.sub(r'**\1**', description)
# Check if this description is expanded is_expanded = index in st.session_state.expanded_descriptions # Show full or truncated description based on state if len(description) > 500 and not is_expanded: st.write(description[:500] + "...") if st.button("See more", key=f"expand_{index}"): st.session_state.expanded_descriptions.add(index) st.rerun() # Show truncated or full description based on state if len(description) > 500: if not job_key in st.session_state.expanded_descriptions: st.session_state.expanded_descriptions[job_key] = False if st.session_state.expanded_descriptions[job_key]: st.markdown(description) if st.button("Show Less", key=f"button_{index}_less"): st.session_state.expanded_descriptions[job_key] = False st.rerun() else: st.markdown(description[:500] + "...") if st.button("Show More", key=f"button_{index}_more"): st.session_state.expanded_descriptions[job_key] = True st.rerun() else: st.write(description) if len(description) > 500 and st.button("See less", key=f"collapse_{index}"): st.session_state.expanded_descriptions.remove(index) st.rerun() st.markdown(description) else: st.warning(""" No matching jobs found. Try:app.py+61-55