Spaces:
Running
Running
Update model.py
Browse files
model.py
CHANGED
@@ -1,30 +1,57 @@
|
|
1 |
-
import
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
4 |
|
5 |
-
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
def modelFeedback(ats_score, resume_data):
|
13 |
input_prompt = f"""
|
14 |
You are now an ATS Score analyzer and given ATS Score is {int(ats_score * 100)}%.
|
15 |
Your task is to provide feedback to the user based on the ATS score.
|
16 |
Print ATS score first. Mention where the resume is good and where the resume lacks.
|
17 |
-
|
|
|
|
|
|
|
18 |
Resume Data: {resume_data}
|
|
|
19 |
"""
|
20 |
-
|
21 |
-
# Tokenize the input to check its length
|
22 |
-
input_ids = tokenizer(input_prompt, return_tensors="pt").input_ids
|
23 |
-
input_length = input_ids.shape[1]
|
24 |
-
|
25 |
-
print(f"Input length: {input_length}")
|
26 |
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
-
|
|
|
|
|
|
1 |
+
import csv
|
2 |
+
import io
|
3 |
+
import requests
|
4 |
+
import json
|
5 |
+
import html # For escaping HTML characters
|
6 |
+
from bs4 import BeautifulSoup
|
7 |
+
from openai import OpenAI
|
8 |
|
9 |
+
# Initialize OpenAI API with Nvidia's Llama 3.1 70b nemotron model
|
10 |
+
client = OpenAI(
|
11 |
+
base_url="https://integrate.api.nvidia.com/v1",
|
12 |
+
api_key="KEY"
|
13 |
+
)
|
14 |
|
15 |
+
def clean_text_output(text):
|
16 |
+
"""
|
17 |
+
Cleans the output to handle HTML characters and unwanted tags.
|
18 |
+
"""
|
19 |
+
text = html.unescape(text) # Unescape HTML entities
|
20 |
+
soup = BeautifulSoup(text, 'html.parser') # Use BeautifulSoup to handle HTML tags
|
21 |
+
cleaned_text = soup.get_text(separator="\n").strip() # Remove tags and handle newlines
|
22 |
+
return cleaned_text
|
23 |
|
24 |
+
def modelFeedback(ats_score, resume_data, job_description):
|
25 |
input_prompt = f"""
|
26 |
You are now an ATS Score analyzer and given ATS Score is {int(ats_score * 100)}%.
|
27 |
Your task is to provide feedback to the user based on the ATS score.
|
28 |
Print ATS score first. Mention where the resume is good and where the resume lacks.
|
29 |
+
Show list of missing skills and suggest improvements.
|
30 |
+
Show list of weak action verbs and suggest improvements.
|
31 |
+
Show weaker sentences and suggest improvements.
|
32 |
+
Talk about each section of the user's resume and discuss good and bad points of it only if it has any.
|
33 |
Resume Data: {resume_data}
|
34 |
+
Job Description: {job_description}
|
35 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
+
try:
|
38 |
+
# Generate response using the OpenAI API
|
39 |
+
response = client.chat.completions.create(
|
40 |
+
model="nvidia/llama-3.1-nemotron-70b-instruct", # Using Llama 3.1 70b
|
41 |
+
messages=[
|
42 |
+
{"role": "user", "content": input_prompt}
|
43 |
+
],
|
44 |
+
temperature=0.03, # Lowering temperature for precise output
|
45 |
+
top_p=0.7, # Prioritize high-probability tokens
|
46 |
+
max_tokens=700, # Allow longer content
|
47 |
+
)
|
48 |
+
|
49 |
+
# Extract and clean the response
|
50 |
+
feedback_text = response.choices[0].message.content.strip() # Corrected line
|
51 |
+
cleaned_feedback = clean_text_output(feedback_text)
|
52 |
+
|
53 |
+
return cleaned_feedback
|
54 |
|
55 |
+
except requests.exceptions.RequestException as e:
|
56 |
+
print(f"API request failed: {str(e)}")
|
57 |
+
return "Error: Unable to generate feedback."
|