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."