Spaces:
Sleeping
Sleeping
import gradio as gr | |
import pandas as pd | |
import datetime | |
import numpy as np | |
from transformers import pipeline | |
class AIHRAgent: | |
def __init__(self): | |
self.resume_scanner = pipeline("zero-shot-classification", model="facebook/bart-large-mnli") | |
self.employee_records = pd.DataFrame(columns=["Name", "Position", "Start Date", "Attendance", "Performance", "Leaves"]) | |
self.company_policies = "Employees are entitled to 24 annual leaves and must adhere to company policies regarding attendance and punctuality." | |
def screen_resume(self, resume_text, job_description): | |
results = self.resume_scanner(resume_text, candidate_labels=[job_description, "Not Relevant"]) | |
return f"Relevance Score: {results['scores'][0]:.2f} for the position of {job_description}." | |
def onboarding_guide(self, employee_name, position): | |
return f"Welcome {employee_name}! As a {position}, your first day involves orientation, meeting the team, and setting up your work systems." | |
def add_employee(self, name, position, start_date): | |
new_employee = { | |
"Name": name, | |
"Position": position, | |
"Start Date": start_date, | |
"Attendance": 0, | |
"Performance": "Not Reviewed", | |
"Leaves": 0 | |
} | |
self.employee_records = self.employee_records.append(new_employee, ignore_index=True) | |
return f"Employee {name} added successfully." | |
def track_attendance(self, employee_name): | |
if employee_name in self.employee_records["Name"].values: | |
self.employee_records.loc[self.employee_records["Name"] == employee_name, "Attendance"] += 1 | |
return f"Attendance recorded for {employee_name}." | |
return f"Employee {employee_name} not found." | |
def process_payroll(self, employee_name, base_salary): | |
if employee_name in self.employee_records["Name"].values: | |
tax = base_salary * 0.1 | |
net_salary = base_salary - tax | |
return f"Payroll Processed: Gross Salary = {base_salary}, Tax = {tax}, Net Salary = {net_salary}." | |
return f"Employee {employee_name} not found." | |
def pulse_survey(self): | |
return "Pulse Survey: On a scale of 1-5, how satisfied are you with your current role?" | |
def feedback_analysis(self, feedback_scores): | |
avg_score = np.mean(feedback_scores) | |
return f"Average Engagement Score: {avg_score:.2f}. Action Needed: {'Yes' if avg_score < 3 else 'No'}." | |
def performance_review(self, employee_name, review_score): | |
if employee_name in self.employee_records["Name"].values: | |
self.employee_records.loc[self.employee_records["Name"] == employee_name, "Performance"] = review_score | |
return f"Performance of {employee_name} updated to {review_score}." | |
return f"Employee {employee_name} not found." | |
def get_policy(self): | |
return self.company_policies | |
def exit_interview(self, employee_name, feedback): | |
if employee_name in self.employee_records["Name"].values: | |
self.employee_records = self.employee_records[self.employee_records["Name"] != employee_name] | |
return f"Exit interview recorded for {employee_name}. Feedback: {feedback}" | |
return f"Employee {employee_name} not found." | |
ai_hr = AIHRAgent() | |
def gradio_interface(): | |
with gr.Blocks() as interface: | |
gr.Markdown("# **AI HR Agent**") | |
gr.Markdown("Automate all HR functionalities with an intelligent AI agent.") | |
with gr.Tab("Recruitment and Onboarding"): | |
resume_input = gr.Textbox(label="Paste Resume Text") | |
job_description_input = gr.Textbox(label="Job Description") | |
resume_output = gr.Textbox(label="Screening Result") | |
screen_button = gr.Button("Screen Resume") | |
onboarding_name = gr.Textbox(label="Employee Name") | |
onboarding_position = gr.Textbox(label="Position") | |
onboarding_output = gr.Textbox(label="Onboarding Guide") | |
onboarding_button = gr.Button("Generate Onboarding Guide") | |
with gr.Tab("Employee Management"): | |
add_name = gr.Textbox(label="Employee Name") | |
add_position = gr.Textbox(label="Position") | |
add_start_date = gr.Textbox(label="Start Date (YYYY-MM-DD)") | |
add_output = gr.Textbox(label="Add Employee Result") | |
add_button = gr.Button("Add Employee") | |
attendance_name = gr.Textbox(label="Employee Name for Attendance") | |
attendance_output = gr.Textbox(label="Attendance Result") | |
attendance_button = gr.Button("Record Attendance") | |
with gr.Tab("Payroll Management"): | |
payroll_name = gr.Textbox(label="Employee Name") | |
payroll_salary = gr.Number(label="Base Salary") | |
payroll_output = gr.Textbox(label="Payroll Result") | |
payroll_button = gr.Button("Process Payroll") | |
with gr.Tab("Employee Engagement"): | |
pulse_output = gr.Textbox(label="Pulse Survey") | |
pulse_button = gr.Button("Get Pulse Survey") | |
feedback_scores = gr.Textbox(label="Feedback Scores (comma-separated)") | |
feedback_output = gr.Textbox(label="Feedback Analysis Result") | |
feedback_button = gr.Button("Analyze Feedback") | |
with gr.Tab("Performance Management"): | |
review_name = gr.Textbox(label="Employee Name") | |
review_score = gr.Number(label="Review Score") | |
review_output = gr.Textbox(label="Review Result") | |
review_button = gr.Button("Update Performance Review") | |
with gr.Tab("Compliance and Policy Management"): | |
policy_output = gr.Textbox(label="Company Policies") | |
policy_button = gr.Button("View Policies") | |
with gr.Tab("Exit Management"): | |
exit_name = gr.Textbox(label="Employee Name") | |
exit_feedback = gr.Textbox(label="Exit Feedback") | |
exit_output = gr.Textbox(label="Exit Interview Result") | |
exit_button = gr.Button("Record Exit Interview") | |
screen_button.click(ai_hr.screen_resume, inputs=[resume_input, job_description_input], outputs=resume_output) | |
onboarding_button.click(ai_hr.onboarding_guide, inputs=[onboarding_name, onboarding_position], outputs=onboarding_output) | |
add_button.click(ai_hr.add_employee, inputs=[add_name, add_position, add_start_date], outputs=add_output) | |
attendance_button.click(ai_hr.track_attendance, inputs=attendance_name, outputs=attendance_output) | |
payroll_button.click(ai_hr.process_payroll, inputs=[payroll_name, payroll_salary], outputs=payroll_output) | |
pulse_button.click(lambda: ai_hr.pulse_survey(), outputs=pulse_output) | |
feedback_button.click(lambda scores: ai_hr.feedback_analysis(list(map(int, scores.split(',')))), inputs=feedback_scores, outputs=feedback_output) | |
review_button.click(ai_hr.performance_review, inputs=[review_name, review_score], outputs=review_output) | |
policy_button.click(lambda: ai_hr.get_policy(), outputs=policy_output) | |
exit_button.click(ai_hr.exit_interview, inputs=[exit_name, exit_feedback], outputs=exit_output) | |
return interface | |
interface = gradio_interface() | |
interface.launch(share=True) |