Spaces:
Sleeping
Sleeping
Update app.py
Browse files9 unmodified lines1011121314151617181920212223242526272829303132333435363738394041424344454647484950515253100 unmodified lines1541551561571581591 unmodified line16116216316416516616716816917017117217317424 unmodified lines1992002012022032042052062072082092103 unmodified lines2142152162172182192202212222232242252262272281 unmodified line2302312322332342352362372382392402412422432442452462472482499 unmodified linesif pd.isna(salary_str):return 0salary_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) / 2return int(avg_hourly * HOURS_PER_YEAR)# 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)# 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 stringif 'k' in salary_str:low *= 1000high *= 1000return int((low + high) // 2)# 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)# Extract plain numbersnumbers = re.findall(r'\d+\.?\d*', salary_str)if numbers:# Take the first number foundsalary = float(numbers[0])# If the number is small (likely in thousands), multiply by 1000if salary < 1000:salary *= 1000100 unmodified linesst.title("Job Search Application")st.write("Find jobs that match your preferences!")# Load dataurl = "https://huggingface.co/datasets/burcuonel/datajob_indeed_usa/raw/main/datajob_indeed_usa.csv"jobs_df = load_and_preprocess_data(url)1 unmodified lineif jobs_df is None:return# Initialize session stateif 'search_performed' not in st.session_state:st.session_state.search_performed = Falseif '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 filterswith st.sidebar:st.header("Search Filters")24 unmodified lines)st.session_state.search_performed = True# Reset expanded descriptions when new search is performedst.session_state.expanded_descriptions = set()if st.button("Reset Filters", use_container_width=True):st.session_state.search_performed = Falsest.session_state.filtered_jobs = pd.DataFrame()st.session_state.expanded_descriptions = set()st.rerun()# Display results3 unmodified linesif 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']}")if 'cluster' in row:st.write(f"**Cluster:** {row['cluster']}")st.write("**Description:**")description = row['Description']# Highlight keywordsif keywords:keyword_list = [k.strip() for k in keywords.split(',')]for keyword in keyword_list:1 unmodified linepattern = re.compile(f'({re.escape(keyword)})', re.IGNORECASE)description = pattern.sub(r'**\1**', description)# Check if this description is expandedis_expanded = index in st.session_state.expanded_descriptions# Show full or truncated description based on stateif 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()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()else:st.warning("""No matching jobs found. Try:9 unmodified lines10111213141516171819202122232425262728293031323334353637383940414243444546474849100 unmodified lines1501511521531541551561571581591601611621631 unmodified line16516616716816917024 unmodified lines1951961971981992002012022032042052063 unmodified lines2102112122132142152162172182192202212222232242252262272282292302311 unmodified line2332342352362372382392402412422432442452462472482492502512522532542559 unmodified linesif pd.isna(salary_str):return 0# Debug printst.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# First, clean up special characters and standardize format# Convert em-dashes and other dash-like characters to regular hyphenssalary_str = salary_str.replace('−', '-').replace('–', '-')# Remove duplicate hyphenssalary_str = re.sub(r'-+', '-', salary_str)# Debug print after cleaningst.write(f"Cleaned salary string: {salary_str}")# Extract all numbers from the stringnumbers = [float(num) for num in re.findall(r'\d+\.?\d*', salary_str)]# Debug print numbers foundst.write(f"Found numbers: {numbers}")if len(numbers) >= 2:min_salary = min(numbers)max_salary = max(numbers)if min_salary < max_salary: # Only use as range if numbers are differentaverage = (min_salary + max_salary) / 2st.write(f"Calculated average: {average}")return int(average)# If we haven't returned by now, process as single numberif numbers:salary = max(numbers) # Use the largest number found# If the number is small (likely in thousands), multiply by 1000if salary < 1000:salary *= 1000100 unmodified linesst.title("Job Search Application")st.write("Find jobs that match your preferences!")# Initialize session state for expanded descriptionsif '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 = Falseif 'filtered_jobs' not in st.session_state:st.session_state.filtered_jobs = pd.DataFrame()# Load dataurl = "https://huggingface.co/datasets/burcuonel/datajob_indeed_usa/raw/main/datajob_indeed_usa.csv"jobs_df = load_and_preprocess_data(url)1 unmodified lineif jobs_df is None:return# Sidebar filterswith st.sidebar:st.header("Search Filters")24 unmodified lines)st.session_state.search_performed = True# Reset expanded descriptions when new search is performedst.session_state.expanded_descriptions = {}if st.button("Reset Filters", use_container_width=True):st.session_state.search_performed = Falsest.session_state.filtered_jobs = pd.DataFrame()st.session_state.expanded_descriptions = {}st.rerun()# Display results3 unmodified linesif not filtered_jobs.empty:for index, row in filtered_jobs.iterrows():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 if anyif keywords:keyword_list = [k.strip() for k in keywords.split(',')]for keyword in keyword_list:1 unmodified linepattern = re.compile(f'({re.escape(keyword)})', re.IGNORECASE)description = pattern.sub(r'**\1**', description)# Show truncated or full description based on stateif len(description) > 500:if not job_key in st.session_state.expanded_descriptions:st.session_state.expanded_descriptions[job_key] = Falseif 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] = Falsest.rerun()else:st.markdown(description[:500] + "...")if st.button("Show More", key=f"button_{index}_more"):st.session_state.expanded_descriptions[job_key] = Truest.rerun()else:st.markdown(description)else:st.warning("""No matching jobs found. Try:
app.py+61-55