Spaces:
Sleeping
Sleeping
Update utils/suggestions.py
Browse files- utils/suggestions.py +23 -31
utils/suggestions.py
CHANGED
|
@@ -1,42 +1,34 @@
|
|
| 1 |
-
from transformers import
|
| 2 |
import torch
|
| 3 |
|
| 4 |
-
# Load
|
| 5 |
-
|
|
|
|
| 6 |
model = AutoModelForCausalLM.from_pretrained(
|
| 7 |
-
|
| 8 |
-
torch_dtype=torch.float32
|
| 9 |
-
device_map="auto"
|
| 10 |
)
|
|
|
|
| 11 |
|
| 12 |
-
def call_llm(prompt
|
| 13 |
-
|
| 14 |
-
|
| 15 |
with torch.no_grad():
|
| 16 |
-
|
| 17 |
-
input_ids,
|
| 18 |
-
max_new_tokens=
|
| 19 |
do_sample=True,
|
| 20 |
-
|
| 21 |
-
|
| 22 |
)
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
# Remove prompt from output if repeated
|
| 26 |
-
return output.replace(prompt, "").strip()
|
| 27 |
-
|
| 28 |
-
def get_certification_suggestions(text: str) -> str:
|
| 29 |
-
prompt = f"Suggest top professional certifications to help advance this person's career:\n{text}"
|
| 30 |
-
return call_llm(prompt)
|
| 31 |
|
| 32 |
-
def
|
| 33 |
-
prompt = f"
|
| 34 |
-
return call_llm(prompt)
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
return call_llm(prompt)
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
| 1 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 2 |
import torch
|
| 3 |
|
| 4 |
+
# Load ungated Phi-2 model
|
| 5 |
+
model_name = "microsoft/phi-2"
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
model = AutoModelForCausalLM.from_pretrained(
|
| 8 |
+
model_name,
|
| 9 |
+
torch_dtype=torch.float32
|
|
|
|
| 10 |
)
|
| 11 |
+
model.eval()
|
| 12 |
|
| 13 |
+
def call_llm(prompt):
|
| 14 |
+
inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
|
|
|
|
| 15 |
with torch.no_grad():
|
| 16 |
+
outputs = model.generate(
|
| 17 |
+
inputs["input_ids"],
|
| 18 |
+
max_new_tokens=250,
|
| 19 |
do_sample=True,
|
| 20 |
+
temperature=0.7,
|
| 21 |
+
top_k=50
|
| 22 |
)
|
| 23 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
def get_certification_suggestions(cv_text):
|
| 26 |
+
prompt = f"""You are a helpful career assistant. Analyze the following CV content and suggest relevant certifications to improve the candidate's chances of getting international jobs.
|
|
|
|
| 27 |
|
| 28 |
+
CV:
|
| 29 |
+
{cv_text}
|
|
|
|
| 30 |
|
| 31 |
+
List the top 5 certifications with short descriptions.
|
| 32 |
+
"""
|
| 33 |
+
response = call_llm(prompt)
|
| 34 |
+
return response.strip()
|