Spaces:
Sleeping
Sleeping
from agentpro import AgentPro | |
from agentpro.tools import AresInternetTool, CodeEngine | |
import requests | |
from bs4 import BeautifulSoup | |
import PyPDF2 | |
import io | |
import docx | |
from typing import Dict, List, Optional | |
class HiringAgent: | |
def __init__(self): | |
self.agent = AgentPro(tools=[AresInternetTool(), CodeEngine()]) | |
def extract_text_from_pdf(self, pdf_url: str) -> str: | |
"""Extract text from PDF file.""" | |
response = requests.get(pdf_url) | |
pdf_file = io.BytesIO(response.content) | |
pdf_reader = PyPDF2.PdfReader(pdf_file) | |
text = "" | |
for page in pdf_reader.pages: | |
text += page.extract_text() | |
return text | |
def extract_text_from_docx(self, docx_url: str) -> str: | |
"""Extract text from DOCX file.""" | |
response = requests.get(docx_url) | |
docx_file = io.BytesIO(response.content) | |
doc = docx.Document(docx_file) | |
text = "" | |
for paragraph in doc.paragraphs: | |
text += paragraph.text + "\n" | |
return text | |
def analyze_github_profile(self, github_url: str) -> Dict: | |
"""Analyze GitHub profile and extract relevant information.""" | |
response = requests.get(github_url) | |
soup = BeautifulSoup(response.text, 'html.parser') | |
# Extract basic information | |
name = soup.find('span', {'class': 'p-name'}).text.strip() if soup.find('span', {'class': 'p-name'}) else "" | |
bio = soup.find('div', {'class': 'p-note'}).text.strip() if soup.find('div', {'class': 'p-note'}) else "" | |
# Extract repositories | |
repos = [] | |
for repo in soup.find_all('a', {'data-hovercard-type': 'repository'})[:5]: | |
repos.append({ | |
'name': repo.text.strip(), | |
'url': f"https://github.com{repo['href']}" | |
}) | |
return { | |
'name': name, | |
'bio': bio, | |
'repositories': repos | |
} | |
def analyze_candidate(self, resume_url: str, github_url: str, job_description: str, company_info: str) -> Dict: | |
"""Analyze candidate profile and generate assessment.""" | |
# Extract resume text | |
if resume_url.endswith('.pdf'): | |
resume_text = self.extract_text_from_pdf(resume_url) | |
elif resume_url.endswith('.docx'): | |
resume_text = self.extract_text_from_docx(resume_url) | |
else: | |
resume_text = "" | |
# Analyze GitHub profile | |
github_data = self.analyze_github_profile(github_url) | |
# Generate assessment using AgentPro | |
prompt = f""" | |
Analyze this candidate profile and provide a detailed assessment: | |
Resume Content: | |
{resume_text} | |
GitHub Profile: | |
Name: {github_data['name']} | |
Bio: {github_data['bio']} | |
Top Repositories: {[repo['name'] for repo in github_data['repositories']]} | |
Job Description: | |
{job_description} | |
Company Information: | |
{company_info} | |
Please provide (Generate 40 tokens max per point/topic): | |
1. Skills and experience match with job requirements | |
2. Technical proficiency assessment | |
3. Cultural fit analysis | |
4. Strengths and areas for development | |
5. Overall recommendations | |
""" | |
assessment = self.agent(prompt) | |
return { | |
'resume_analysis': resume_text, | |
'github_analysis': github_data, | |
'assessment': assessment | |
} |