gaur3009 commited on
Commit
0d98f00
·
verified ·
1 Parent(s): 420920f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -39
app.py CHANGED
@@ -2,20 +2,54 @@ import gradio as gr
2
  import pandas as pd
3
  import datetime
4
  import numpy as np
5
- from transformers import pipeline
 
 
6
 
7
  class AIHRAgent:
8
  def __init__(self):
9
- self.resume_scanner = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
 
10
  self.employee_records = pd.DataFrame(columns=["Name", "Position", "Start Date", "Attendance", "Performance", "Leaves"])
11
  self.company_policies = "Employees are entitled to 24 annual leaves and must adhere to company policies regarding attendance and punctuality."
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  def screen_resume(self, resume_text, job_description):
14
- results = self.resume_scanner(resume_text, candidate_labels=[job_description, "Not Relevant"])
15
- return f"Relevance Score: {results['scores'][0]:.2f} for the position of {job_description}."
 
 
 
 
 
 
 
 
 
 
16
 
17
  def onboarding_guide(self, employee_name, position):
18
- return f"Welcome {employee_name}! As a {position}, your first day involves orientation, meeting the team, and setting up your work systems."
 
 
 
 
 
 
19
 
20
  def add_employee(self, name, position, start_date):
21
  new_employee = {
@@ -64,23 +98,28 @@ class AIHRAgent:
64
  return f"Exit interview recorded for {employee_name}. Feedback: {feedback}"
65
  return f"Employee {employee_name} not found."
66
 
 
67
  ai_hr = AIHRAgent()
68
 
 
69
  def gradio_interface():
70
  with gr.Blocks() as interface:
71
- gr.Markdown("# **AI HR Agent**")
72
- gr.Markdown("Automate all HR functionalities with an intelligent AI agent.")
73
 
74
  with gr.Tab("Recruitment and Onboarding"):
75
- resume_input = gr.Textbox(label="Paste Resume Text")
76
- job_description_input = gr.Textbox(label="Job Description")
77
- resume_output = gr.Textbox(label="Screening Result")
78
- screen_button = gr.Button("Screen Resume")
79
-
80
- onboarding_name = gr.Textbox(label="Employee Name")
81
- onboarding_position = gr.Textbox(label="Position")
82
- onboarding_output = gr.Textbox(label="Onboarding Guide")
83
- onboarding_button = gr.Button("Generate Onboarding Guide")
 
 
 
84
 
85
  with gr.Tab("Employee Management"):
86
  add_name = gr.Textbox(label="Employee Name")
@@ -99,42 +138,26 @@ def gradio_interface():
99
  payroll_output = gr.Textbox(label="Payroll Result")
100
  payroll_button = gr.Button("Process Payroll")
101
 
102
- with gr.Tab("Employee Engagement"):
103
- pulse_output = gr.Textbox(label="Pulse Survey")
104
- pulse_button = gr.Button("Get Pulse Survey")
105
-
106
- feedback_scores = gr.Textbox(label="Feedback Scores (comma-separated)")
107
- feedback_output = gr.Textbox(label="Feedback Analysis Result")
108
- feedback_button = gr.Button("Analyze Feedback")
109
-
110
- with gr.Tab("Performance Management"):
111
- review_name = gr.Textbox(label="Employee Name")
112
- review_score = gr.Number(label="Review Score")
113
- review_output = gr.Textbox(label="Review Result")
114
- review_button = gr.Button("Update Performance Review")
115
-
116
- with gr.Tab("Compliance and Policy Management"):
117
- policy_output = gr.Textbox(label="Company Policies")
118
- policy_button = gr.Button("View Policies")
119
-
120
  with gr.Tab("Exit Management"):
121
  exit_name = gr.Textbox(label="Employee Name")
122
  exit_feedback = gr.Textbox(label="Exit Feedback")
123
  exit_output = gr.Textbox(label="Exit Interview Result")
124
  exit_button = gr.Button("Record Exit Interview")
125
 
126
- screen_button.click(ai_hr.screen_resume, inputs=[resume_input, job_description_input], outputs=resume_output)
 
 
 
 
 
127
  onboarding_button.click(ai_hr.onboarding_guide, inputs=[onboarding_name, onboarding_position], outputs=onboarding_output)
128
  add_button.click(ai_hr.add_employee, inputs=[add_name, add_position, add_start_date], outputs=add_output)
129
  attendance_button.click(ai_hr.track_attendance, inputs=attendance_name, outputs=attendance_output)
130
  payroll_button.click(ai_hr.process_payroll, inputs=[payroll_name, payroll_salary], outputs=payroll_output)
131
- pulse_button.click(lambda: ai_hr.pulse_survey(), outputs=pulse_output)
132
- feedback_button.click(lambda scores: ai_hr.feedback_analysis(list(map(int, scores.split(',')))), inputs=feedback_scores, outputs=feedback_output)
133
- review_button.click(ai_hr.performance_review, inputs=[review_name, review_score], outputs=review_output)
134
- policy_button.click(lambda: ai_hr.get_policy(), outputs=policy_output)
135
  exit_button.click(ai_hr.exit_interview, inputs=[exit_name, exit_feedback], outputs=exit_output)
136
 
137
  return interface
138
 
 
139
  interface = gradio_interface()
140
  interface.launch(share=True)
 
2
  import pandas as pd
3
  import datetime
4
  import numpy as np
5
+ import docx
6
+ from PyPDF2 import PdfReader
7
+ from sentence_transformers import SentenceTransformer, util
8
 
9
  class AIHRAgent:
10
  def __init__(self):
11
+ # Advanced model for semantic similarity
12
+ self.resume_model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
13
  self.employee_records = pd.DataFrame(columns=["Name", "Position", "Start Date", "Attendance", "Performance", "Leaves"])
14
  self.company_policies = "Employees are entitled to 24 annual leaves and must adhere to company policies regarding attendance and punctuality."
15
 
16
+ def extract_text_from_file(self, file_path):
17
+ """Extract text from uploaded file (PDF or DOCX)."""
18
+ try:
19
+ if file_path.name.endswith(".pdf"):
20
+ pdf_reader = PdfReader(file_path)
21
+ text = " ".join(page.extract_text() for page in pdf_reader.pages if page.extract_text())
22
+ elif file_path.name.endswith(".docx"):
23
+ doc = docx.Document(file_path)
24
+ text = " ".join(paragraph.text for paragraph in doc.paragraphs)
25
+ else:
26
+ raise ValueError("Unsupported file format. Please upload a PDF or DOCX file.")
27
+ return text
28
+ except Exception as e:
29
+ return f"Error extracting text from file: {e}"
30
+
31
  def screen_resume(self, resume_text, job_description):
32
+ """Advanced resume screening using sentence embeddings."""
33
+ try:
34
+ if not resume_text or not job_description:
35
+ return "Please provide both the resume text and job description."
36
+
37
+ # Semantic similarity scoring
38
+ job_embedding = self.resume_model.encode(job_description, convert_to_tensor=True)
39
+ resume_embedding = self.resume_model.encode(resume_text, convert_to_tensor=True)
40
+ similarity = util.pytorch_cos_sim(job_embedding, resume_embedding).item()
41
+ return f"Relevance Score: {similarity:.2f} for the position of {job_description}."
42
+ except Exception as e:
43
+ return f"Error during resume screening: {e}"
44
 
45
  def onboarding_guide(self, employee_name, position):
46
+ """Automated onboarding guide generation."""
47
+ return (f"Welcome {employee_name}!\n"
48
+ f"As a {position}, your onboarding plan includes:\n"
49
+ f"1. Orientation session.\n"
50
+ f"2. Team introductions.\n"
51
+ f"3. Work system setup.\n"
52
+ f"4. Initial training and goal setting.")
53
 
54
  def add_employee(self, name, position, start_date):
55
  new_employee = {
 
98
  return f"Exit interview recorded for {employee_name}. Feedback: {feedback}"
99
  return f"Employee {employee_name} not found."
100
 
101
+ # AI HR Agent Instance
102
  ai_hr = AIHRAgent()
103
 
104
+ # Gradio Interface
105
  def gradio_interface():
106
  with gr.Blocks() as interface:
107
+ gr.Markdown("# **Advanced AI HR Agent**")
108
+ gr.Markdown("This AI automates all HR tasks and provides advanced features such as resume screening and policy management.")
109
 
110
  with gr.Tab("Recruitment and Onboarding"):
111
+ with gr.Row():
112
+ with gr.Column():
113
+ resume_upload = gr.File(label="Upload Resume (PDF/DOCX)")
114
+ job_description_input = gr.Textbox(label="Job Description")
115
+ resume_screen_output = gr.Textbox(label="Screening Result")
116
+ screen_button = gr.Button("Screen Resume")
117
+
118
+ with gr.Column():
119
+ onboarding_name = gr.Textbox(label="Employee Name")
120
+ onboarding_position = gr.Textbox(label="Position")
121
+ onboarding_output = gr.Textbox(label="Onboarding Guide")
122
+ onboarding_button = gr.Button("Generate Onboarding Guide")
123
 
124
  with gr.Tab("Employee Management"):
125
  add_name = gr.Textbox(label="Employee Name")
 
138
  payroll_output = gr.Textbox(label="Payroll Result")
139
  payroll_button = gr.Button("Process Payroll")
140
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  with gr.Tab("Exit Management"):
142
  exit_name = gr.Textbox(label="Employee Name")
143
  exit_feedback = gr.Textbox(label="Exit Feedback")
144
  exit_output = gr.Textbox(label="Exit Interview Result")
145
  exit_button = gr.Button("Record Exit Interview")
146
 
147
+ # Button Actions
148
+ screen_button.click(
149
+ lambda file, job_desc: ai_hr.screen_resume(ai_hr.extract_text_from_file(file), job_desc) if file else "No resume file uploaded.",
150
+ inputs=[resume_upload, job_description_input],
151
+ outputs=resume_screen_output,
152
+ )
153
  onboarding_button.click(ai_hr.onboarding_guide, inputs=[onboarding_name, onboarding_position], outputs=onboarding_output)
154
  add_button.click(ai_hr.add_employee, inputs=[add_name, add_position, add_start_date], outputs=add_output)
155
  attendance_button.click(ai_hr.track_attendance, inputs=attendance_name, outputs=attendance_output)
156
  payroll_button.click(ai_hr.process_payroll, inputs=[payroll_name, payroll_salary], outputs=payroll_output)
 
 
 
 
157
  exit_button.click(ai_hr.exit_interview, inputs=[exit_name, exit_feedback], outputs=exit_output)
158
 
159
  return interface
160
 
161
+ # Launch Interface
162
  interface = gradio_interface()
163
  interface.launch(share=True)