Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,79 +1,75 @@
|
|
1 |
-
from fastapi import FastAPI, HTTPException, UploadFile, File
|
2 |
-
import pandas as pd
|
3 |
-
from resume_extractor import ResumeExtractor
|
4 |
-
from job_description_extractor import JobDescriptionExtractor
|
5 |
-
from model_trainer import ModelTrainer
|
6 |
-
from comparison_utils import (
|
7 |
-
compare_with_chatgpt_job_title,
|
8 |
-
compare_with_chatgpt_education,
|
9 |
-
compare_with_chatgpt_location,
|
10 |
-
compare_age_range_with_description
|
11 |
-
)
|
12 |
-
from synthetic_data import create_synthetic_data
|
13 |
-
|
14 |
-
app = FastAPI()
|
15 |
-
|
16 |
-
def main(resume_text, job_description):
|
17 |
-
openai_api_key = 'sk-proj-bC6H6QrP6DUqHkn5vOkYT3BlbkFJsSyvL4Bc9c3UEbHrsPMj'
|
18 |
-
ner_model_name_or_path = "NLPclass/Named-entity-recognition"
|
19 |
-
skill_model_name_or_path = "GalalEwida/lm-ner-skills-recognition"
|
20 |
-
|
21 |
-
resume_extractor = ResumeExtractor(ner_model_name_or_path, openai_api_key)
|
22 |
-
job_description_extractor = JobDescriptionExtractor(openai_api_key)
|
23 |
-
|
24 |
-
full_name, loc, age, skills, education_resume, title_job_resume = resume_extractor.extract_resume_info(resume_text, skill_model_name_or_path)
|
25 |
-
job_skills, education_job, title_job, location, age_DS = job_description_extractor.extract_job_info(job_description, skill_model_name_or_path)
|
26 |
-
|
27 |
-
education_match = compare_with_chatgpt_education(education_resume, education_job, openai_api_key)
|
28 |
-
title_job_match = compare_with_chatgpt_job_title(title_job_resume, title_job, openai_api_key)
|
29 |
-
title_loc_match = compare_with_chatgpt_location(loc, location, openai_api_key)
|
30 |
-
title_age_match = compare_age_range_with_description(age, age_DS, openai_api_key)
|
31 |
-
|
32 |
-
synthetic_data = create_synthetic_data(job_skills, education_job, title_job, location, age_DS)
|
33 |
-
synthetic_data.to_csv('synthetic_data.csv')
|
34 |
-
model_trainer = ModelTrainer(synthetic_data)
|
35 |
-
best_model = model_trainer.train_models()
|
36 |
-
|
37 |
-
input_data = {skill: 1 if skill in skills else 0 for skill in job_skills}
|
38 |
-
input_data[education_job] = education_match
|
39 |
-
input_data[title_job] = title_job_match
|
40 |
-
input_data[location] = title_loc_match
|
41 |
-
input_data[age_DS] = title_age_match
|
42 |
-
|
43 |
-
input_df = pd.DataFrame([input_data])
|
44 |
-
input_df.to_csv('input_df.csv')
|
45 |
-
predicted_target = best_model.predict(input_df)
|
46 |
-
|
47 |
-
return {
|
48 |
-
"full_name": full_name,
|
49 |
-
"location": loc,
|
50 |
-
"age": age,
|
51 |
-
"age_DS": age_DS,
|
52 |
-
"skills": skills,
|
53 |
-
"education_resume": education_resume,
|
54 |
-
"title_job_resume": title_job_resume,
|
55 |
-
"job_skills": job_skills,
|
56 |
-
"education_job": education_job,
|
57 |
-
"title_job": title_job,
|
58 |
-
"location_job": location,
|
59 |
-
"predicted_target": predicted_target[0]
|
60 |
-
}
|
61 |
-
|
62 |
-
@app.post("/extract")
|
63 |
-
async def extract(resume_file: UploadFile = File(...), job_description_file: UploadFile = File(...)):
|
64 |
-
try:
|
65 |
-
resume_text = await resume_file.read()
|
66 |
-
job_description = await job_description_file.read()
|
67 |
-
|
68 |
-
# Convert bytes to string
|
69 |
-
resume_text = resume_text.decode('utf-8')
|
70 |
-
job_description = job_description.decode('utf-8')
|
71 |
-
|
72 |
-
output = main(resume_text, job_description)
|
73 |
-
return output
|
74 |
-
except Exception as e:
|
75 |
-
raise HTTPException(status_code=500, detail=str(e))
|
76 |
-
|
77 |
-
if __name__ == "__main__":
|
78 |
-
import uvicorn
|
79 |
-
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
|
1 |
+
from fastapi import FastAPI, HTTPException, UploadFile, File
|
2 |
+
import pandas as pd
|
3 |
+
from resume_extractor import ResumeExtractor
|
4 |
+
from job_description_extractor import JobDescriptionExtractor
|
5 |
+
from model_trainer import ModelTrainer
|
6 |
+
from comparison_utils import (
|
7 |
+
compare_with_chatgpt_job_title,
|
8 |
+
compare_with_chatgpt_education,
|
9 |
+
compare_with_chatgpt_location,
|
10 |
+
compare_age_range_with_description
|
11 |
+
)
|
12 |
+
from synthetic_data import create_synthetic_data
|
13 |
+
|
14 |
+
app = FastAPI()
|
15 |
+
|
16 |
+
def main(resume_text, job_description):
|
17 |
+
openai_api_key = 'sk-proj-bC6H6QrP6DUqHkn5vOkYT3BlbkFJsSyvL4Bc9c3UEbHrsPMj'
|
18 |
+
ner_model_name_or_path = "NLPclass/Named-entity-recognition"
|
19 |
+
skill_model_name_or_path = "GalalEwida/lm-ner-skills-recognition"
|
20 |
+
|
21 |
+
resume_extractor = ResumeExtractor(ner_model_name_or_path, openai_api_key)
|
22 |
+
job_description_extractor = JobDescriptionExtractor(openai_api_key)
|
23 |
+
|
24 |
+
full_name, loc, age, skills, education_resume, title_job_resume = resume_extractor.extract_resume_info(resume_text, skill_model_name_or_path)
|
25 |
+
job_skills, education_job, title_job, location, age_DS = job_description_extractor.extract_job_info(job_description, skill_model_name_or_path)
|
26 |
+
|
27 |
+
education_match = compare_with_chatgpt_education(education_resume, education_job, openai_api_key)
|
28 |
+
title_job_match = compare_with_chatgpt_job_title(title_job_resume, title_job, openai_api_key)
|
29 |
+
title_loc_match = compare_with_chatgpt_location(loc, location, openai_api_key)
|
30 |
+
title_age_match = compare_age_range_with_description(age, age_DS, openai_api_key)
|
31 |
+
|
32 |
+
synthetic_data = create_synthetic_data(job_skills, education_job, title_job, location, age_DS)
|
33 |
+
synthetic_data.to_csv('synthetic_data.csv')
|
34 |
+
model_trainer = ModelTrainer(synthetic_data)
|
35 |
+
best_model = model_trainer.train_models()
|
36 |
+
|
37 |
+
input_data = {skill: 1 if skill in skills else 0 for skill in job_skills}
|
38 |
+
input_data[education_job] = education_match
|
39 |
+
input_data[title_job] = title_job_match
|
40 |
+
input_data[location] = title_loc_match
|
41 |
+
input_data[age_DS] = title_age_match
|
42 |
+
|
43 |
+
input_df = pd.DataFrame([input_data])
|
44 |
+
input_df.to_csv('input_df.csv')
|
45 |
+
predicted_target = best_model.predict(input_df)
|
46 |
+
|
47 |
+
return {
|
48 |
+
"full_name": full_name,
|
49 |
+
"location": loc,
|
50 |
+
"age": age,
|
51 |
+
"age_DS": age_DS,
|
52 |
+
"skills": skills,
|
53 |
+
"education_resume": education_resume,
|
54 |
+
"title_job_resume": title_job_resume,
|
55 |
+
"job_skills": job_skills,
|
56 |
+
"education_job": education_job,
|
57 |
+
"title_job": title_job,
|
58 |
+
"location_job": location,
|
59 |
+
"predicted_target": predicted_target[0]
|
60 |
+
}
|
61 |
+
|
62 |
+
@app.post("/extract")
|
63 |
+
async def extract(resume_file: UploadFile = File(...), job_description_file: UploadFile = File(...)):
|
64 |
+
try:
|
65 |
+
resume_text = await resume_file.read()
|
66 |
+
job_description = await job_description_file.read()
|
67 |
+
|
68 |
+
# Convert bytes to string
|
69 |
+
resume_text = resume_text.decode('utf-8')
|
70 |
+
job_description = job_description.decode('utf-8')
|
71 |
+
|
72 |
+
output = main(resume_text, job_description)
|
73 |
+
return output
|
74 |
+
except Exception as e:
|
75 |
+
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
|
|
|