Spaces:
Sleeping
Sleeping
Update app.py
Browse files9 unmodified lines101112131415161718192021222324252627282930313233343536373839404142434445464748495051525319 unmodified lines7374757677789 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 *= 1000return int(salary)return 019 unmodified linesst.error(f"Error loading data: {str(e)}")return Nonedef find_matching_jobs(df, job_title, location, min_salary, keywords, debug=True):"""Find matching jobs using simple filtering first."""matches = df.copy()9 unmodified lines101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737419 unmodified lines9495969798991009 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 annual salary ranges (e.g., "100,440-223,680 a year" or "100,440−100,440−223,680 a year")# First, clean up multiple dashes and convert them to a single dashcleaned_str = re.sub(r'−+', '-', salary_str) # Replace multiple em-dashes with hyphencleaned_str = re.sub(r'-+', '-', cleaned_str) # Replace multiple hyphens with single hyphen# Look for salary range patternrange_match = re.search(r'(\d+\.?\d*)\s*k?\s*-\s*(\d+\.?\d*)\s*k?', cleaned_str)if range_match:nums = [float(x) for x in range_match.groups()]# Convert if 'k' is in the stringif 'k' in salary_str:nums = [x * 1000 for x in nums]low = min(nums)high = max(nums)return 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:nums = [float(x) for x in numbers]# If multiple numbers found, assume it's a rangeif len(nums) >= 2:low = min(nums)high = max(nums)# If the numbers are small (likely in thousands), multiply by 1000if high < 1000:low *= 1000high *= 1000return int((low + high) // 2)else:# Single number foundsalary = nums[0]# If the number is small (likely in thousands), multiply by 1000if salary < 1000:salary *= 1000return int(salary)return 019 unmodified linesst.error(f"Error loading data: {str(e)}")return Nonedef find_matching_jobs(df, job_title, location, min_salary, keywords, debug=True):"""Find matching jobs using simple filtering first."""matches = df.copy()
app.py+49-27