Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -12,7 +12,6 @@ app = Flask(__name__)
|
|
12 |
n_gpu_layers = 0
|
13 |
n_batch = 1024
|
14 |
|
15 |
-
|
16 |
llm = LlamaCpp(
|
17 |
model_path="Phi-3-mini-4k-instruct-q4.gguf", # path to GGUF file
|
18 |
temperature=0.1,
|
@@ -21,23 +20,22 @@ llm = LlamaCpp(
|
|
21 |
verbose=True,
|
22 |
n_ctx=4096
|
23 |
)
|
24 |
-
model0 = AutoModel.from_pretrained('sentence-transformers/paraphrase-TinyBERT-L6-v2'
|
25 |
|
26 |
model = SentenceTransformer('sentence-transformers/paraphrase-TinyBERT-L6-v2')
|
27 |
|
28 |
file_size = os.stat('Phi-3-mini-4k-instruct-q4.gguf')
|
29 |
print("model size ====> :", file_size.st_size, "bytes")
|
30 |
|
31 |
-
|
32 |
@app.route('/cv', methods=['POST'])
|
33 |
def get_skills():
|
34 |
cv_body = request.json.get('cv_body')
|
35 |
|
36 |
# Simple inference example
|
37 |
output = llm(
|
38 |
-
f"
|
39 |
max_tokens=256, # Generate up to 256 tokens
|
40 |
-
stop=["
|
41 |
echo=True, # Whether to echo the prompt
|
42 |
)
|
43 |
|
@@ -47,13 +45,15 @@ def get_skills():
|
|
47 |
def health():
|
48 |
return jsonify({'status': 'Worked'})
|
49 |
|
50 |
-
#
|
51 |
-
# the llm will say the most similar job to the cv
|
52 |
@app.route('/compare', methods=['POST'])
|
53 |
def compare():
|
54 |
employee_skills = request.json.get('employee_skills')
|
55 |
jobs_skills = request.json.get('jobs_skills')
|
56 |
|
|
|
|
|
|
|
57 |
if not isinstance(jobs_skills, list) or not all(isinstance(skill, str) for skill in jobs_skills):
|
58 |
raise ValueError("jobs_skills must be a list of strings")
|
59 |
|
@@ -69,18 +69,21 @@ def compare():
|
|
69 |
similarity_scores.append({"job": jobs_skills[i], "similarity_score": similarity_score.item()})
|
70 |
|
71 |
return jsonify(similarity_scores)
|
|
|
|
|
72 |
@app.route('/compare_jop', methods=['POST'])
|
73 |
def compare_jop():
|
74 |
employee_skills = request.json.get('post')
|
75 |
jobs_skills = request.json.get('employee_skills')
|
76 |
|
77 |
if not isinstance(employee_skills, list) or not all(isinstance(skill, str) for skill in employee_skills):
|
78 |
-
raise ValueError("post must be a list of strings")
|
79 |
-
if not isinstance(jobs_skills, list) or not all(isinstance(skill, str) for skill in jobs_skills):
|
80 |
raise ValueError("employee_skills must be a list of strings")
|
81 |
|
82 |
-
|
|
|
|
|
83 |
job_embeddings = model.encode(jobs_skills)
|
|
|
84 |
|
85 |
similarity_scores = []
|
86 |
employee_embeddings_tensor = torch.from_numpy(employee_embeddings).unsqueeze(0)
|
@@ -92,7 +95,5 @@ def compare_jop():
|
|
92 |
|
93 |
return jsonify(similarity_scores)
|
94 |
|
95 |
-
|
96 |
-
|
97 |
if __name__ == '__main__':
|
98 |
-
app.run()
|
|
|
12 |
n_gpu_layers = 0
|
13 |
n_batch = 1024
|
14 |
|
|
|
15 |
llm = LlamaCpp(
|
16 |
model_path="Phi-3-mini-4k-instruct-q4.gguf", # path to GGUF file
|
17 |
temperature=0.1,
|
|
|
20 |
verbose=True,
|
21 |
n_ctx=4096
|
22 |
)
|
23 |
+
model0 = AutoModel.from_pretrained('sentence-transformers/paraphrase-TinyBERT-L6-v2')
|
24 |
|
25 |
model = SentenceTransformer('sentence-transformers/paraphrase-TinyBERT-L6-v2')
|
26 |
|
27 |
file_size = os.stat('Phi-3-mini-4k-instruct-q4.gguf')
|
28 |
print("model size ====> :", file_size.st_size, "bytes")
|
29 |
|
|
|
30 |
@app.route('/cv', methods=['POST'])
|
31 |
def get_skills():
|
32 |
cv_body = request.json.get('cv_body')
|
33 |
|
34 |
# Simple inference example
|
35 |
output = llm(
|
36 |
+
f"\n{cv_body}\nCan you list the skills mentioned in the CV?",
|
37 |
max_tokens=256, # Generate up to 256 tokens
|
38 |
+
stop=[""],
|
39 |
echo=True, # Whether to echo the prompt
|
40 |
)
|
41 |
|
|
|
45 |
def health():
|
46 |
return jsonify({'status': 'Worked'})
|
47 |
|
48 |
+
# Endpoint to compare between employee skills and job skills
|
|
|
49 |
@app.route('/compare', methods=['POST'])
|
50 |
def compare():
|
51 |
employee_skills = request.json.get('employee_skills')
|
52 |
jobs_skills = request.json.get('jobs_skills')
|
53 |
|
54 |
+
if not isinstance(employee_skills, list) or not all(isinstance(skill, str) for skill in employee_skills):
|
55 |
+
raise ValueError("employee_skills must be a list of strings")
|
56 |
+
|
57 |
if not isinstance(jobs_skills, list) or not all(isinstance(skill, str) for skill in jobs_skills):
|
58 |
raise ValueError("jobs_skills must be a list of strings")
|
59 |
|
|
|
69 |
similarity_scores.append({"job": jobs_skills[i], "similarity_score": similarity_score.item()})
|
70 |
|
71 |
return jsonify(similarity_scores)
|
72 |
+
|
73 |
+
# Endpoint to compare job posts with employee skills
|
74 |
@app.route('/compare_jop', methods=['POST'])
|
75 |
def compare_jop():
|
76 |
employee_skills = request.json.get('post')
|
77 |
jobs_skills = request.json.get('employee_skills')
|
78 |
|
79 |
if not isinstance(employee_skills, list) or not all(isinstance(skill, str) for skill in employee_skills):
|
|
|
|
|
80 |
raise ValueError("employee_skills must be a list of strings")
|
81 |
|
82 |
+
if not isinstance(jobs_skills, list) or not all(isinstance(skill, str) for skill in jobs_skills):
|
83 |
+
raise ValueError("jobs_skills must be a list of strings")
|
84 |
+
|
85 |
job_embeddings = model.encode(jobs_skills)
|
86 |
+
employee_embeddings = model.encode(employee_skills)
|
87 |
|
88 |
similarity_scores = []
|
89 |
employee_embeddings_tensor = torch.from_numpy(employee_embeddings).unsqueeze(0)
|
|
|
95 |
|
96 |
return jsonify(similarity_scores)
|
97 |
|
|
|
|
|
98 |
if __name__ == '__main__':
|
99 |
+
app.run()
|