Spaces:
Sleeping
Sleeping
Update utils/suggestions.py
Browse files- utils/suggestions.py +53 -33
utils/suggestions.py
CHANGED
|
@@ -1,48 +1,68 @@
|
|
| 1 |
-
import pandas as pd
|
| 2 |
import os
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
|
| 6 |
def load_csv(filename):
|
| 7 |
-
path = os.path.join(
|
| 8 |
return pd.read_csv(path)
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
def match_field(field, df):
|
| 11 |
-
|
| 12 |
-
match
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
def get_certification_suggestions(
|
|
|
|
| 18 |
df = load_csv("certifications.csv")
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
-
def get_higher_education_suggestions(
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
def get_visa_recommendations(
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
def get_career_advice(
|
|
|
|
| 30 |
df = load_csv("career_advice.csv")
|
| 31 |
-
|
|
|
|
| 32 |
|
| 33 |
def get_job_listings(parsed_text):
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
for _, row in jobs_df.iterrows():
|
| 40 |
-
job_keywords = row["keywords"].split(",")
|
| 41 |
-
if any(kw.lower() in [k.lower() for k in keywords] for kw in job_keywords):
|
| 42 |
-
matched_jobs.append(f"{row['title']} at {row['company']} ({row['location']})")
|
| 43 |
-
|
| 44 |
-
if not matched_jobs:
|
| 45 |
-
return ["No job listings found for your field."]
|
| 46 |
-
|
| 47 |
-
return matched_jobs
|
| 48 |
-
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import pandas as pd
|
| 3 |
|
| 4 |
+
CSV_FOLDER = os.path.join(os.path.dirname(__file__), '../csvs')
|
| 5 |
|
| 6 |
def load_csv(filename):
|
| 7 |
+
path = os.path.join(CSV_FOLDER, filename)
|
| 8 |
return pd.read_csv(path)
|
| 9 |
|
| 10 |
+
def extract_field_from_text(text):
|
| 11 |
+
# Dummy implementation: extract the main field keyword from the parsed CV text
|
| 12 |
+
# You should replace this with your actual field extraction logic or pass field directly
|
| 13 |
+
keywords = [
|
| 14 |
+
"accounting", "agriculture", "architecture", "artificial intelligence", "biology",
|
| 15 |
+
"business analysis", "chemistry", "civil engineering", "data science", "dentistry",
|
| 16 |
+
"electrical engineering", "finance", "graphic design", "healthcare", "hospitality",
|
| 17 |
+
"information technology", "journalism", "law", "marketing", "mechanical engineering",
|
| 18 |
+
"nursing", "pharmacy", "psychology", "quality assurance", "robotics", "sales",
|
| 19 |
+
"software development", "statistics", "teaching", "ux design", "veterinary",
|
| 20 |
+
"web development", "x-ray technology", "youth counseling", "zoology"
|
| 21 |
+
]
|
| 22 |
+
text_lower = text.lower()
|
| 23 |
+
for kw in keywords:
|
| 24 |
+
if kw in text_lower:
|
| 25 |
+
return kw
|
| 26 |
+
return "general" # fallback
|
| 27 |
+
|
| 28 |
def match_field(field, df):
|
| 29 |
+
field_lower = field.lower()
|
| 30 |
+
# Try exact match first
|
| 31 |
+
matched = df[df['field'].str.lower() == field_lower]
|
| 32 |
+
if matched.empty:
|
| 33 |
+
# Try contains match for partial matches
|
| 34 |
+
matched = df[df['field'].str.lower().str.contains(field_lower)]
|
| 35 |
+
if matched.empty:
|
| 36 |
+
# fallback: return empty dataframe
|
| 37 |
+
return pd.DataFrame()
|
| 38 |
+
return matched
|
| 39 |
|
| 40 |
+
def get_certification_suggestions(parsed_text):
|
| 41 |
+
field = extract_field_from_text(parsed_text)
|
| 42 |
df = load_csv("certifications.csv")
|
| 43 |
+
matched = match_field(field, df)
|
| 44 |
+
return matched['suggestion'].tolist()
|
| 45 |
|
| 46 |
+
def get_higher_education_suggestions(parsed_text):
|
| 47 |
+
field = extract_field_from_text(parsed_text)
|
| 48 |
+
df = load_csv("higher_education.csv")
|
| 49 |
+
matched = match_field(field, df)
|
| 50 |
+
return matched['suggestion'].tolist()
|
| 51 |
|
| 52 |
+
def get_visa_recommendations(parsed_text):
|
| 53 |
+
field = extract_field_from_text(parsed_text)
|
| 54 |
+
df = load_csv("visa_recommendations.csv")
|
| 55 |
+
matched = match_field(field, df)
|
| 56 |
+
return matched['suggestion'].tolist()
|
| 57 |
|
| 58 |
+
def get_career_advice(parsed_text):
|
| 59 |
+
field = extract_field_from_text(parsed_text)
|
| 60 |
df = load_csv("career_advice.csv")
|
| 61 |
+
matched = match_field(field, df)
|
| 62 |
+
return matched['suggestion'].tolist()
|
| 63 |
|
| 64 |
def get_job_listings(parsed_text):
|
| 65 |
+
field = extract_field_from_text(parsed_text)
|
| 66 |
+
df = load_csv("job_listings.csv")
|
| 67 |
+
matched = match_field(field, df)
|
| 68 |
+
return matched['listing'].tolist()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|