Spaces:
Sleeping
Sleeping
| import os | |
| import pandas as pd | |
| import pandas as pd | |
| import os | |
| CSV_FOLDER = os.path.join(os.path.dirname(__file__), "..", "csvs") | |
| def load_csv(filename): | |
| path = os.path.join(CSV_FOLDER, filename) | |
| df = pd.read_csv(path) | |
| df.columns = df.columns.str.strip().str.lower() # Normalize headers | |
| return df | |
| def extract_field_from_text(text): | |
| # Dummy implementation: extract the main field keyword from the parsed CV text | |
| # You should replace this with your actual field extraction logic or pass field directly | |
| keywords = [ | |
| "accounting", "agriculture", "architecture", "artificial intelligence", "biology", | |
| "business analysis", "chemistry", "civil engineering", "data science", "dentistry", | |
| "electrical engineering", "finance", "graphic design", "healthcare", "hospitality", | |
| "information technology", "journalism", "law", "marketing", "mechanical engineering", | |
| "nursing", "pharmacy", "psychology", "quality assurance", "robotics", "sales", | |
| "software development", "statistics", "teaching", "ux design", "veterinary", | |
| "web development", "x-ray technology", "youth counseling", "zoology" | |
| ] | |
| text_lower = text.lower() | |
| for kw in keywords: | |
| if kw in text_lower: | |
| return kw | |
| return "general" # fallback | |
| def match_field(field, df): | |
| field = field.lower() | |
| if "field" not in df.columns or "suggestion" not in df.columns: | |
| raise KeyError("CSV file must have 'field' and 'suggestion' columns.") | |
| match = df[df['field'].str.lower().str.contains(field, na=False)] | |
| return match | |
| def get_certification_suggestions(parsed_text): | |
| field = extract_field_from_text(parsed_text) | |
| df = load_csv("certifications.csv") | |
| matched = match_field(field, df) | |
| return matched['suggestion'].tolist() | |
| def get_higher_education_suggestions(parsed_text): | |
| field = extract_field_from_text(parsed_text) | |
| df = load_csv("higher_education.csv") | |
| matched = match_field(field, df) | |
| return matched['suggestion'].tolist() | |
| def get_visa_recommendations(parsed_text): | |
| field = extract_field_from_text(parsed_text) | |
| df = load_csv("visa_recommendations.csv") | |
| matched = match_field(field, df) | |
| return matched['suggestion'].tolist() | |
| def get_career_advice(parsed_text): | |
| field = extract_field_from_text(parsed_text) | |
| df = load_csv("career_advice.csv") | |
| matched = match_field(field, df) | |
| return matched['suggestion'].tolist() | |
| def get_job_listings(cv_text): | |
| df = load_csv("jobs.csv") | |
| field = identify_field(cv_text) | |
| matched = match_field(field, df) | |
| # Handle either 'listing' or 'suggestion' key | |
| for col in ['listing', 'suggestion']: | |
| if col in matched.columns: | |
| return matched[col].dropna().tolist() | |
| raise KeyError("CSV file must have either 'listing' or 'suggestion' column.") | |
| def identify_field(cv_text): | |
| # A basic mock-up: you should replace this with actual NLP/ML logic | |
| lower_text = cv_text.lower() | |
| if "python" in lower_text or "software" in lower_text or "developer" in lower_text: | |
| return "Software Development" | |
| elif "accounting" in lower_text or "finance" in lower_text: | |
| return "Accounting" | |
| elif "nurse" in lower_text or "clinical" in lower_text: | |
| return "Nursing" | |
| elif "biology" in lower_text: | |
| return "Biology" | |
| elif "marketing" in lower_text: | |
| return "Marketing" | |
| else: | |
| return "General" | |