import csv import io import os 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 a comprehensive review and feedback based on the ATS score. ### ATS Score: The current ATS score is {int(ats_score * 100)}%. Your goal is to increase this score by aligning the resume more closely with the job description. This is the model I am using "model = SentenceTransformer('paraphrase-MiniLM-L6-v2') # Pre-trained BERT model" so make sure the ats score imporvemnts is based on this model. ### Overall Resume Review: Please assess the following key aspects of the resume and provide specific feedback where necessary. In each case, suggest improvements, if any: Show overall resume rating out of 100 and matching with job description out of 100 with titles 'Resume Score' and 'Matching Score' 1. **Quantifying Impact**: Are accomplishments supported by measurable data or metrics? Suggest improvements if more quantifiable results could be provided. 2. **Unique Action Verbs**: Are there any unique or strong action verbs? Highlight any overused verbs and suggest stronger alternatives. 3. **Weak Action Verbs**: Identify any weak or passive verbs and provide suggestions to improve them. 4. **Verb Tenses**: Check the consistency of verb tenses. Are past roles described using past tense and current roles in present tense? 5. **Accomplishment-Oriented Language**: Is the language focused on achievements rather than responsibilities? Recommend areas where the resume could be more results-driven. 6. **Spell Check**: Identify any spelling or grammatical errors that need to be fixed. 7. **Sections in Resume**: Evaluate each section of the resume (e.g., contact info, experience, education, skills). Are there any missing sections or sections that could be improved? #### Skills Review Table: Please use the table below to summarize key suggestions for improvement: | **Section** | **Good Points** | **Suggestions for Improvement** | |-------------------|------------------------------------------|-----------------------------------------------| | Quantifying Impact| | | | Action Verbs | | | | Verb Tenses | | | | Accomplishments | | | | Spell Check | | | | Sections | | | | Skills | | | ### Matching with Job Description: Now, focus on matching the resume with the job description. Provide detailed feedback on how well the resume aligns with the job description and where it falls short. Suggest specific content that needs to be replaced, added, or modified to improve the ATS score. - **Missing Skills**: Identify any skills from the job description that are missing from the resume and should be added. - **Weak Action Verbs**: Highlight verbs that could be made stronger or more relevant to the job description. - **Weaker Sentences**: Suggest improvements to sentences or bullet points that don't align well with the job description or lack clarity. - **Content to Replace**: List any content in the resume that could be replaced to better match the job description. #### Job Matching Suggestions Table: Use the table below to show specific suggestions for improving the match between the resume and the job description: | **Resume Content** | **Suggested Replacement or Addition** | |----------------------------------|------------------------------------------------------| | (Weaker or Missing Skills) | | | (Weak Action Verbs) | | | (Weaker Sentences or Bullet Points) | | ### Final Recommendations: Conclude the review by summarizing the key areas where the resume can improve both in overall quality and its match with the job description. Provide a strategy for increasing the ATS score by implementing these changes. #### Resume Data: {resume_data} #### Job Description: {job_description} IMPORTANT: The output should be as normal organised text not in any other format (don't give markdown text) and focus more on resume matching part that general resume review. """ 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.01, # Lowering temperature for precise output top_p=0.7, # Prioritize high-probability tokens max_tokens=1500, # 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."