Spaces:
Runtime error
Runtime error
Caitlin Blackmore
commited on
Commit
·
85d30b1
1
Parent(s):
7c993c2
start building out specific job-candidate match functionality
Browse files- main.py +24 -19
- match_utils.py +27 -5
main.py
CHANGED
|
@@ -18,7 +18,7 @@ from localStoragePy import localStoragePy
|
|
| 18 |
localStorage = localStoragePy('pathfinder', 'text')
|
| 19 |
|
| 20 |
from scrape_onet import get_onet_code, get_onet_description, get_onet_tasks
|
| 21 |
-
from match_utils import neighborhoods, get_resume, skillNER, sim_result_loop, get_links, coSkillEmbed, sim_result_loop_jobFinder
|
| 22 |
from user_utils import Hash
|
| 23 |
|
| 24 |
# APP SETUP
|
|
@@ -143,29 +143,30 @@ def get_matches(request: Request):
|
|
| 143 |
@app.post('/find-my-match/', response_class=HTMLResponse)
|
| 144 |
async def post_matches(request: Request, bt: BackgroundTasks, resume: UploadFile = File(...)):
|
| 145 |
|
| 146 |
-
def add_data_to_db(resume
|
|
|
|
|
|
|
| 147 |
embeds = format(coSkillEmbed(resume)).replace('[[','').replace(']]','').split(',')
|
| 148 |
db.iloc[db['username']== username,5:] = embeds
|
| 149 |
db.to_csv('static/res_embeddings.csv', index=False)
|
| 150 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
resume = get_resume(resume)
|
| 152 |
-
username = localStorage.getItem('username')
|
| 153 |
-
db = pd.read_csv('static/res_embeddings.csv')
|
| 154 |
-
|
| 155 |
skills = await skillNER(resume)
|
| 156 |
simResults = await sim_result_loop(resume)
|
| 157 |
links = get_links(simResults[0])
|
| 158 |
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
bt.add_task(add_data_to_db, resume, db, username)
|
| 163 |
|
| 164 |
return templates.TemplateResponse('find_my_match.html', context={'request': request, 'resume': resume, 'skills': skills, 'simResults': simResults[0], 'links': links})
|
| 165 |
|
| 166 |
@app.get("/find-match/", response_class=HTMLResponse)
|
| 167 |
def find_match(request: Request):
|
| 168 |
-
jobselection = str(request.url).split("=")[1].replace('HTTP/1.1', '').replace("-", " ")
|
| 169 |
print(jobselection)
|
| 170 |
return templates.TemplateResponse('find_match.html', context={'request': request, 'jobselection': jobselection})
|
| 171 |
|
|
@@ -176,27 +177,31 @@ def get_hires(request: Request):
|
|
| 176 |
# POST
|
| 177 |
@app.post('/find-my-hire/', response_class=HTMLResponse)
|
| 178 |
async def post_matches(request: Request, bt: BackgroundTasks, jobdesc: UploadFile = File(...)):
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
def add_data_to_db(resume, db, username):
|
| 185 |
-
embeds = format(coSkillEmbed(resume)).replace('[[','').replace(']]','').split(',')
|
| 186 |
db.iloc[db['username']== username,5:] = embeds
|
| 187 |
db.to_csv('static/jd_embeddings.csv', index=False)
|
| 188 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
skills = await skillNER(jobdesc)
|
| 190 |
simResults = await sim_result_loop(jobdesc)
|
| 191 |
links = get_links(simResults[0])
|
| 192 |
|
| 193 |
-
bt.add_task(add_data_to_db, jobdesc
|
|
|
|
| 194 |
|
| 195 |
return templates.TemplateResponse('candidate_matcher.html', context={'request': request, 'jobdesc': jobdesc, 'skills': skills, 'simResults': simResults[0], 'links': links})
|
| 196 |
|
| 197 |
@app.get("/find-hire/", response_class=HTMLResponse)
|
| 198 |
def find_hire(request: Request):
|
| 199 |
-
jobselection = str(request.url).split("=")[1].replace('HTTP/1.1', '').replace("-", " ")
|
| 200 |
print(jobselection)
|
| 201 |
return templates.TemplateResponse('find_hire.html', context={'request': request, 'jobselection': jobselection})
|
| 202 |
|
|
|
|
| 18 |
localStorage = localStoragePy('pathfinder', 'text')
|
| 19 |
|
| 20 |
from scrape_onet import get_onet_code, get_onet_description, get_onet_tasks
|
| 21 |
+
from match_utils import neighborhoods, get_resume, skillNER, sim_result_loop, get_links, coSkillEmbed, sim_result_loop_jobFinder, sim_result_loop_candFinder
|
| 22 |
from user_utils import Hash
|
| 23 |
|
| 24 |
# APP SETUP
|
|
|
|
| 143 |
@app.post('/find-my-match/', response_class=HTMLResponse)
|
| 144 |
async def post_matches(request: Request, bt: BackgroundTasks, resume: UploadFile = File(...)):
|
| 145 |
|
| 146 |
+
def add_data_to_db(resume):
|
| 147 |
+
username = localStorage.getItem('username')
|
| 148 |
+
db = pd.read_csv('static/res_embeddings.csv')
|
| 149 |
embeds = format(coSkillEmbed(resume)).replace('[[','').replace(']]','').split(',')
|
| 150 |
db.iloc[db['username']== username,5:] = embeds
|
| 151 |
db.to_csv('static/res_embeddings.csv', index=False)
|
| 152 |
|
| 153 |
+
def get_jobs_from_db(resume):
|
| 154 |
+
job_matches = sim_result_loop_jobFinder(resume)
|
| 155 |
+
print(job_matches)
|
| 156 |
+
|
| 157 |
resume = get_resume(resume)
|
|
|
|
|
|
|
|
|
|
| 158 |
skills = await skillNER(resume)
|
| 159 |
simResults = await sim_result_loop(resume)
|
| 160 |
links = get_links(simResults[0])
|
| 161 |
|
| 162 |
+
bt.add_task(add_data_to_db, resume)
|
| 163 |
+
bt.add_task(get_jobs_from_db, resume)
|
|
|
|
|
|
|
| 164 |
|
| 165 |
return templates.TemplateResponse('find_my_match.html', context={'request': request, 'resume': resume, 'skills': skills, 'simResults': simResults[0], 'links': links})
|
| 166 |
|
| 167 |
@app.get("/find-match/", response_class=HTMLResponse)
|
| 168 |
def find_match(request: Request):
|
| 169 |
+
jobselection = str(request.url).split("=")[1].replace('HTTP/1.1', '').replace("-", " ").replace("%2C", "")
|
| 170 |
print(jobselection)
|
| 171 |
return templates.TemplateResponse('find_match.html', context={'request': request, 'jobselection': jobselection})
|
| 172 |
|
|
|
|
| 177 |
# POST
|
| 178 |
@app.post('/find-my-hire/', response_class=HTMLResponse)
|
| 179 |
async def post_matches(request: Request, bt: BackgroundTasks, jobdesc: UploadFile = File(...)):
|
| 180 |
+
|
| 181 |
+
def add_data_to_db(jobdesc):
|
| 182 |
+
username = localStorage.getItem('username')
|
| 183 |
+
db = pd.read_csv('static/jd_embeddings.csv')
|
| 184 |
+
embeds = format(coSkillEmbed(jobdesc)).replace('[[','').replace(']]','').split(',')
|
|
|
|
|
|
|
| 185 |
db.iloc[db['username']== username,5:] = embeds
|
| 186 |
db.to_csv('static/jd_embeddings.csv', index=False)
|
| 187 |
|
| 188 |
+
def get_cand_from_db(jobdesc):
|
| 189 |
+
cand_matches = sim_result_loop_candFinder(jobdesc)
|
| 190 |
+
print(cand_matches)
|
| 191 |
+
|
| 192 |
+
jobdesc = get_resume(jobdesc)
|
| 193 |
skills = await skillNER(jobdesc)
|
| 194 |
simResults = await sim_result_loop(jobdesc)
|
| 195 |
links = get_links(simResults[0])
|
| 196 |
|
| 197 |
+
bt.add_task(add_data_to_db, jobdesc)
|
| 198 |
+
bt.add_task(get_cand_from_db, jobdesc)
|
| 199 |
|
| 200 |
return templates.TemplateResponse('candidate_matcher.html', context={'request': request, 'jobdesc': jobdesc, 'skills': skills, 'simResults': simResults[0], 'links': links})
|
| 201 |
|
| 202 |
@app.get("/find-hire/", response_class=HTMLResponse)
|
| 203 |
def find_hire(request: Request):
|
| 204 |
+
jobselection = str(request.url).split("=")[1].replace('HTTP/1.1', '').replace("-", " ").replace("%2C", "")
|
| 205 |
print(jobselection)
|
| 206 |
return templates.TemplateResponse('find_hire.html', context={'request': request, 'jobselection': jobselection})
|
| 207 |
|
match_utils.py
CHANGED
|
@@ -119,7 +119,7 @@ def get_links(simResults):
|
|
| 119 |
[links.append("https://www.onetonline.org/link/summary/" + get_onet_code(title)) for title in titles]
|
| 120 |
return links
|
| 121 |
|
| 122 |
-
|
| 123 |
embeds = coSkillEmbed(resume)
|
| 124 |
def cosine(A, B):
|
| 125 |
return np.dot(A,B)/(norm(A)*norm(B))
|
|
@@ -131,10 +131,32 @@ async def sim_result_loop_jobFinder(resume):
|
|
| 131 |
[simResults.append(cosine(np.array(embeds), np.array(jobembeds.iloc[i,:]))) for i in range(len(jobembeds))]
|
| 132 |
simResults = pd.DataFrame(simResults)
|
| 133 |
simResults['job_id'] = jobdat['id']
|
| 134 |
-
simResults =
|
| 135 |
-
simResults
|
| 136 |
-
simResults
|
|
|
|
| 137 |
simResults.reset_index(drop=True, inplace=True)
|
| 138 |
for x in range(len(simResults)):
|
| 139 |
-
simResults.iloc[x,
|
| 140 |
return simResults
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
[links.append("https://www.onetonline.org/link/summary/" + get_onet_code(title)) for title in titles]
|
| 120 |
return links
|
| 121 |
|
| 122 |
+
def sim_result_loop_jobFinder(resume):
|
| 123 |
embeds = coSkillEmbed(resume)
|
| 124 |
def cosine(A, B):
|
| 125 |
return np.dot(A,B)/(norm(A)*norm(B))
|
|
|
|
| 131 |
[simResults.append(cosine(np.array(embeds), np.array(jobembeds.iloc[i,:]))) for i in range(len(jobembeds))]
|
| 132 |
simResults = pd.DataFrame(simResults)
|
| 133 |
simResults['job_id'] = jobdat['id']
|
| 134 |
+
simResults['emp_email'] = jobdat['email']
|
| 135 |
+
simResults = simResults.iloc[:,[1,2,0]]
|
| 136 |
+
simResults.columns = ['job_id', 'employer_email', 'similarity']
|
| 137 |
+
simResults = simResults.sort_values(by = "similarity", ascending = False)
|
| 138 |
simResults.reset_index(drop=True, inplace=True)
|
| 139 |
for x in range(len(simResults)):
|
| 140 |
+
simResults.iloc[x,2] = format_sim(simResults.iloc[x,2])
|
| 141 |
return simResults
|
| 142 |
+
|
| 143 |
+
def sim_result_loop_candFinder(jobdesc):
|
| 144 |
+
embeds = coSkillEmbed(jobdesc)
|
| 145 |
+
def cosine(A, B):
|
| 146 |
+
return np.dot(A,B)/(norm(A)*norm(B))
|
| 147 |
+
def format_sim(sim):
|
| 148 |
+
return "{:0.2f}".format(sim)
|
| 149 |
+
canddat = pd.read_csv('static/res_embeddings.csv')
|
| 150 |
+
candembeds = canddat.iloc[:,5:].dropna()
|
| 151 |
+
simResults = []
|
| 152 |
+
[simResults.append(cosine(np.array(embeds), np.array(candembeds.iloc[i,:]))) for i in range(len(candembeds))]
|
| 153 |
+
simResults = pd.DataFrame(simResults)
|
| 154 |
+
simResults['cand_id'] = canddat['id']
|
| 155 |
+
simResults['cand_email'] = canddat['email']
|
| 156 |
+
simResults = simResults.iloc[:,[1,2,0]]
|
| 157 |
+
simResults.columns = ['candidate_id', 'candidate_email', 'similarity']
|
| 158 |
+
simResults = simResults.sort_values(by = "similarity", ascending = False)
|
| 159 |
+
simResults.reset_index(drop=True, inplace=True)
|
| 160 |
+
for x in range(len(simResults)):
|
| 161 |
+
simResults.iloc[x,2] = format_sim(simResults.iloc[x,2])
|
| 162 |
+
return simResults
|