Spaces:
Sleeping
Sleeping
Update app.py
Browse files9 unmodified lines101112131415131415161721222324251819202122232427282526272829303031313233343533343637383940414243444546363738394041424748495051445253545556575859606162636465664647484950676869707172737419 unmodified lines9495969798991009 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 # 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) # 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) # 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 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 dash cleaned_str = re.sub(r'−+', '-', salary_str) # Replace multiple em-dashes with hyphen cleaned_str = re.sub(r'-+', '-', cleaned_str) # Replace multiple hyphens with single hyphen # Debug print numbers found st.write(f"Found numbers: {numbers}") # Look for salary range pattern range_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 string if 'k' in salary_str: nums = [x * 1000 for x in nums] low = min(nums) high = max(nums) return int((low + high) // 2) 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) # 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 we haven't returned by now, process as single number # Extract plain numbers numbers = re.findall(r'\d+\.?\d*', salary_str) if numbers: nums = [float(x) for x in numbers] # If multiple numbers found, assume it's a range if len(nums) >= 2: low = min(nums) high = max(nums) # If the numbers are small (likely in thousands), multiply by 1000 if high < 1000: low *= 1000 high *= 1000 return int((low + high) // 2) else: # Single number found salary = max(numbers) # Use the largest number found # If the number is small (likely in thousands), multiply by 1000 if salary < 1000: salary *= 1000 return int(salary) salary = nums[0] # If the number is small (likely in thousands), multiply by 1000 if salary < 1000: salary *= 1000 return int(salary) return 0
19 unmodified lines st.error(f"Error loading data: {str(e)}") return None
def 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