File size: 7,262 Bytes
4abd232
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
139
140
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)