File size: 2,248 Bytes
b0c8c8c
 
 
 
 
 
 
7e4deac
b0c8c8c
 
 
6239656
b0c8c8c
0a478f6
b0c8c8c
 
 
 
 
 
 
 
7e4deac
b0c8c8c
7e4deac
81578be
 
 
b0c8c8c
 
 
 
81578be
b0c8c8c
7e4deac
0a478f6
b0c8c8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ad4e39f
b0c8c8c
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import csv
import io
import requests
import json
import html  # For escaping HTML characters
from bs4 import BeautifulSoup
from openai import OpenAI 

# Initialize OpenAI API with Nvidia's Llama 3.1 70b nemotron model
client = OpenAI(
    base_url="https://integrate.api.nvidia.com/v1",
    api_key=os.environ.get("KEY")
)

def clean_text_output(text):
    """
    Cleans the output to handle HTML characters and unwanted tags.
    """
    text = html.unescape(text)  # Unescape HTML entities
    soup = BeautifulSoup(text, 'html.parser')  # Use BeautifulSoup to handle HTML tags
    cleaned_text = soup.get_text(separator="\n").strip()  # Remove tags and handle newlines
    return cleaned_text

def modelFeedback(ats_score, resume_data, job_description):
    input_prompt = f"""
    You are now an ATS Score analyzer and given ATS Score is {int(ats_score * 100)}%. 
    Your task is to provide feedback to the user based on the ATS score.
    Print ATS score first. Mention where the resume is good and where the resume lacks. 
    Show list of missing skills and suggest improvements. 
    Show list of weak action verbs and suggest improvements.
    Show weaker sentences and suggest improvements.
    Talk about each section of the user's resume and discuss good and bad points of it only if it has any. 
    Resume Data: {resume_data}
    Job Description: {job_description}
    """

    try:
        # Generate response using the OpenAI API
        response = client.chat.completions.create(
            model="nvidia/llama-3.1-nemotron-70b-instruct",  # Using Llama 3.1 70b
            messages=[
                {"role": "user", "content": input_prompt}
            ],
            temperature=0.03,  # Lowering temperature for precise output
            top_p=0.7,  # Prioritize high-probability tokens
            max_tokens=700,  # Allow longer content
        )

        # Extract and clean the response
        feedback_text = response.choices[0].message.content.strip()  # Corrected line
        cleaned_feedback = clean_text_output(feedback_text)

        return cleaned_feedback

    except requests.exceptions.RequestException as e:
        print(f"API request failed: {str(e)}")
        return "Error: Unable to generate feedback."