File size: 4,624 Bytes
28c68ad
 
 
ffb6d48
28c68ad
 
 
80ed1fd
28c68ad
 
aaa5ffc
72c1f56
8b348d1
28c68ad
b5ac3f0
28c68ad
 
 
 
 
 
 
 
 
 
 
aef8f8f
28c68ad
7bd332d
b0c8c8c
28c68ad
24ab423
28c68ad
24ab423
28c68ad
 
 
8b348d1
28c68ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fb6c4a2
28c68ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8b348d1
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import streamlit as st
import requests
import logging

# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

# Pre-configured settings (no user input)
system_message = "You are an ATS Score analyzer. Provide clear and constructive feedback to improve the ATS score."
selected_model = "deepseek-ai/DeepSeek-R1-Distill-Qwen-32B"  # Example model
max_tokens = 1500
temperature = 0.1
top_p = 0.6

# Function to query the Hugging Face API
def query(payload, api_url):
    headers = {"Authorization": f"Bearer {st.secrets['KEY2']}"}
    logger.info(f"Sending request to {api_url} with payload: {payload}")
    response = requests.post(api_url, headers=headers, json=payload)
    logger.info(f"Received response: {response.status_code}, {response.text}")
    try:
        return response.json()
    except requests.exceptions.JSONDecodeError:
        logger.error(f"Failed to decode JSON response: {response.text}")
        return None

# Function to generate ATS feedback
def modelFeedback(ats_score, resume_data, job_description):
    """
    Generate ATS feedback using a pre-configured model pipeline.
    """
    # Prepare the input prompt
    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 "deepseek-ai/DeepSeek-R1-Distill-Qwen-32B" so make sure the ats score improvements are 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?
    
    ### 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.
    #### Resume Data: {resume_data}
    #### Job Description: {job_description}
    """

    # Prepare the payload for the API
    payload = {
        "inputs": input_prompt,
        "parameters": {
            "max_new_tokens": max_tokens,
            "temperature": temperature,
            "top_p": top_p,
            "return_full_text": False
        }
    }

    # Construct the API URL based on the selected model
    api_url = f"https://api-inference.huggingface.co/models/{selected_model}"
    logger.info(f"Selected model: {selected_model}, API URL: {api_url}")

    # Query the Hugging Face API
    output = query(payload, api_url)

    # Handle API response
    if output is not None and isinstance(output, list) and len(output) > 0:
        if 'generated_text' in output[0]:
            assistant_response = output[0]['generated_text'].strip()
            logger.info(f"Generated response: {assistant_response}")
            return assistant_response
        else:
            logger.error(f"Unexpected API response structure: {output}")
            return "Error: Unexpected response from the model. Please try again."
    else:
        logger.error(f"Empty or invalid API response: {output}")
        return "Error: Unable to generate a response. Please check the model and try again."