Spaces:
Runtime error
Runtime error
| 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 | |