Spaces:
Runtime error
Runtime error
File size: 6,976 Bytes
8508e0f 87afed1 8508e0f 87afed1 a172d36 87afed1 196b3e3 87afed1 196b3e3 87afed1 eb13e0e 87afed1 196b3e3 87afed1 196b3e3 87afed1 196b3e3 | 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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | import random
import requests
from bs4 import BeautifulSoup
from .constants import API_KEY
def remove_html_tags(text):
text = text.replace("</p>", "\n")
soup = BeautifulSoup(text, "html.parser")
for item in soup.find_all("li"):
item_text = item.get_text()
item.replace_with(f"\n- {item_text}")
cleaned_text = soup.get_text().strip('"').replace('\\"', '"')
return cleaned_text
def api_call(url, payload, headers=None):
headers = {
"x-api-key": API_KEY,
"Content-Type": "application/json"
}
try:
response = requests.post(url, headers=headers, json=payload)
return response
except Exception as e:
print(f"Error: {str(e)}")
return "Error: Unable to reach the API or invalid response received."
def generate_session_id():
return random.randint(3000, 20000)
def highlight_feedback(feedback_output):
if not feedback_output["feedback_by_category"]:
return False, [(str(feedback_output["feedback_text"]), None)]
return True, [(item["text"], item["category"]) for item in feedback_output["feedback_by_category"]]
def show_popup(selected_resume, selected_company, selected_job_description):
if selected_resume:
return """<div id="popup-resume" style="position: fixed; top: 30%; left: 50%; transform: translate(-50%, -50%);
background-color: #fffaf0; border: 2px solid #ffa500; padding: 20px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); border-radius: 10px; z-index: 1000;
color: #ff6700; font-family: Arial, sans-serif; text-align: center;">
<p><strong>Notice:</strong> You selected the option to include the candidate's resume.</p>
<p><a href='https://huggingface.co/spaces/multimodalai/talent-interview-prep/resolve/main/resources/Senior_Product_Manager_Resume.txt'
style='color: #ff6700; text-decoration: none; font-weight: bold;' target="_blank">
Click here to view the resume</a></p>
<button onclick="document.getElementById('popup-resume').remove();"
style="background-color: #ff6700; color: white; border: none;
padding: 5px 10px; border-radius: 5px; cursor: pointer;">
Close
</button>
</div>"""
elif selected_company:
return """<div id="popup-company" style="position: fixed; top: 30%; left: 50%; transform: translate(-50%, -50%);
background-color: #fffaf0; border: 2px solid #ffa500; padding: 20px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); border-radius: 10px; z-index: 1000;
color: #ff6700; font-family: Arial, sans-serif; text-align: center;">
<p><strong>Notice:</strong> You selected the option to include the company name in the request.</p>
<p>The company name is: <strong>InnovateTech Solutions</strong>.</p>
<button onclick="document.getElementById('popup-company').remove();"
style="background-color: #ff6700; color: white; border: none;
padding: 5px 10px; border-radius: 5px; cursor: pointer;">
Close
</button>
</div>"""
elif selected_job_description:
return """<div id="popup-job-desc" style="position: fixed; top: 30%; left: 50%; transform: translate(-50%, -50%);
background-color: #fffaf0; border: 2px solid #ffa500; padding: 20px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); border-radius: 10px; z-index: 1000;
color: #ff6700; font-family: Arial, sans-serif; text-align: center;">
<p><strong>Notice:</strong> You selected the option to include the job description.</p>
<p><a href='https://huggingface.co/spaces/multimodalai/talent-interview-prep/resolve/main/resources/Senior_Product_Manager_Job_Description.txt'
style='color: #ff6700; text-decoration: none; font-weight: bold;' target="_blank">
Click here to view the job description</a></p>
<button onclick="document.getElementById('popup-job-desc').remove();"
style="background-color: #ff6700; color: white; border: none;
padding: 5px 10px; border-radius: 5px; cursor: pointer;">
Close
</button>
</div>"""
return ""
def reset_popup():
return ""
def generate_skills_evaluation_markdown(skills_data):
job_skills = skills_data["job_skills"]
candidate_skills = skills_data["candidate_skills"]["proven_skills"]
unproven_skills = skills_data["candidate_skills"]["mentioned_but_unproven_skills"]
missing_skills = skills_data["candidate_skills"]["missing_skills"]
total_job_skills = len(job_skills)
proven_skills_count = len(candidate_skills)
unproven_skills_count = len(unproven_skills)
missing_skills_count = len(missing_skills)
html = "<div style='text-align: left; font-size: 20px;'>"
html += (
f"<p>The job requires <strong>{total_job_skills} skills</strong>, and the candidate has <strong>{proven_skills_count} proven skills</strong>. "
f"There are <strong>{unproven_skills_count} unproven skills</strong> and <strong>{missing_skills_count} missing skills</strong>.</p><br>"
)
html += "<ul style='font-size: 20px;'>"
if total_job_skills > 0:
html += f"<strong>Job skills ({total_job_skills}):</strong><ol style='font-size: 18px;'>"
for skill in job_skills:
html += f"<li> <strong>{skill['name']}</strong> - {skill['description']}</li>"
html += "</ol>"
if proven_skills_count > 0:
html += f"<strong>Candidate skills ({proven_skills_count} out of {total_job_skills}):</strong><ol style='font-size: 18px;'>"
for skill in candidate_skills:
html += (f"<li><strong>{skill['name']}</strong><br>"
f" <em>Example:</em> {skill['example']}<br>"
f" <em>Metrics:</em> {skill['metrics']}</li>")
html += "</ol>"
if unproven_skills_count > 0:
html += "<strong>Mentioned but unproven skills:</strong>"
html += "<ol style='font-size: 18px;'>"
for skill in unproven_skills:
html += f"<li><strong>{skill['name']}</strong> - {skill['reason']}</li>"
html += "</ol>"
if missing_skills_count > 0:
html += "<strong>Missing skills:</strong>"
html += "<ol style='font-size: 18px;'>"
for skill in missing_skills:
html += f"<li><strong>{skill['name']}</strong> - {skill['reason']}</li>"
html += "</ol>"
html += "</ul></div>"
return html
|