File size: 3,294 Bytes
28c68ad
 
 
ffb6d48
28c68ad
 
 
80ed1fd
28c68ad
 
aaa5ffc
777c494
98e580b
28c68ad
b5ac3f0
28c68ad
 
 
 
 
 
 
 
 
 
 
aef8f8f
28c68ad
7bd332d
b0c8c8c
28c68ad
24ab423
28c68ad
24ab423
28c68ad
 
 
8b348d1
28c68ad
 
777c494
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
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 = 500
temperature = 0.4
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.
    
    ### Matching with Job Description:
    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."