Karthikeyan commited on
Commit
c5002df
1 Parent(s): 41d1f17

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +137 -0
app.py ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import PyPDF2
3
+ import os
4
+ import openai
5
+ import re
6
+ import plotly.graph_objects as go
7
+
8
+ class ResumeAnalyser:
9
+ def __init__(self):
10
+ pass
11
+ def extract_text_from_file(self,file_path):
12
+ # Get the file extension
13
+ file_extension = os.path.splitext(file_path)[1]
14
+
15
+ if file_extension == '.pdf':
16
+ with open(file_path, 'rb') as file:
17
+ # Create a PDF file reader object
18
+ reader = PyPDF2.PdfFileReader(file)
19
+
20
+ # Create an empty string to hold the extracted text
21
+ extracted_text = ""
22
+
23
+ # Loop through each page in the PDF and extract the text
24
+ for page_number in range(reader.getNumPages()):
25
+ page = reader.getPage(page_number)
26
+ extracted_text += page.extractText()
27
+ return extracted_text
28
+
29
+ elif file_extension == '.txt':
30
+ with open(file_path, 'r') as file:
31
+ # Just read the entire contents of the text file
32
+ return file.read()
33
+
34
+ else:
35
+ return "Unsupported file type"
36
+
37
+ def responce_from_ai(self,textjd, textcv):
38
+ resume = self.extract_text_from_file(textjd)
39
+ job_description = self.extract_text_from_file(textcv)
40
+
41
+ response = openai.Completion.create(
42
+ engine="text-davinci-003",
43
+ prompt=f"""
44
+ Given the job description and the resume, assess the matching percentage to 100 and if 100 percentage not matched mention the remaining percentage with reason. **Job Description:**{job_description}**Resume:**{resume}
45
+ **Detailed Analysis:**
46
+ the result should be in this format:
47
+ Matched Percentage: [matching percentage].
48
+ Reason : [reason for Matched Percentage].
49
+ Skills To Improve : [Mention the skills to improve and get 100 percentage matching].
50
+ Keywords : [matched key words from {job_description} and {resume}].
51
+ """,
52
+ temperature=0,
53
+ max_tokens=100,
54
+ n=1,
55
+ stop=None,
56
+ )
57
+ generated_text = response.choices[0].text.strip()
58
+ print(generated_text)
59
+ return generated_text
60
+
61
+
62
+ def matching_percentage(self,job_description_path, resume_path):
63
+
64
+ job_description_path = job_description_path.name
65
+ resume_path = resume_path.name
66
+
67
+ generated_text = self.responce_from_ai(job_description_path, resume_path)
68
+
69
+ result = generated_text
70
+
71
+ match = re.search(r"(Matched Percentage: (.+))", result)
72
+ percentage = match.group(1)
73
+
74
+ match = re.search(r"(Reason: (.+))", result)
75
+ reason = match.group(1)
76
+
77
+ match = re.search(r"(Skills To Improve: (.+))", result)
78
+ skills = match.group(1)
79
+
80
+ match = re.search(r"(Keywords: (.+))", result)
81
+ keywords = match.group(1)
82
+
83
+
84
+ # Extract the matched percentage using regular expression
85
+ match1 = re.search(r"Matched Percentage: (\d+)%", percentage)
86
+ matched_percentage = int(match1.group(1))
87
+
88
+ # Creating a pie chart with plotly
89
+ labels = ['Matched', 'Remaining']
90
+ values = [matched_percentage, 100 - matched_percentage]
91
+
92
+ fig = go.Figure(data=[go.Pie(labels=labels, values=values)])
93
+ # fig.update_layout(title='Matched Percentage')
94
+
95
+
96
+ return percentage,reason, skills, keywords,fig
97
+
98
+
99
+ def gradio_interface(self):
100
+ with gr.Blocks(css="style.css",theme=gr.themes.Soft()) as app:
101
+ gr.HTML("""<img class="leftimage" align="left" src="https://companieslogo.com/img/orig/RAND.AS_BIG-0f1935a4.png?t=1651813778" alt="Image" width="210" height="210">
102
+ <img class="rightimage" align="right" src="https://workllama.com/wp-content/uploads/2022/05/WL_Logo.svg" alt="Image" width="210" height="210">""")
103
+
104
+ with gr.Row():
105
+ with gr.Column(elem_id="col-container"):
106
+ gr.HTML(
107
+ """<br style="color:white;">"""
108
+ )
109
+ gr.HTML(
110
+ """<h2 style="text-align:center; color:"white">WorkLLama Resume Matcher</h2> """
111
+ )
112
+ gr.HTML("<br>")
113
+ with gr.Row():
114
+ with gr.Column(scale=0.45, min_width=150, ):
115
+ jobDescription = gr.File(label="Job Description")
116
+ with gr.Column(scale=0.45, min_width=150):
117
+ resume = gr.File(label="Resume")
118
+ with gr.Column(scale=0.10, min_width=150):
119
+ analyse = gr.Button("Analyse")
120
+ with gr.Row():
121
+ with gr.Column(scale=1.0, min_width=150):
122
+ perncentage = gr.Textbox(label="Matching Percentage",lines=8)
123
+ with gr.Column(scale=1.0, min_width=150):
124
+ reason = gr.Textbox(label="Reason",lines=8)
125
+ with gr.Column(scale=1.0, min_width=150):
126
+ skills = gr.Textbox(label="Skills",lines=8)
127
+ with gr.Column(scale=1.0, min_width=150):
128
+ keywords = gr.Textbox(label="Keywords",lines=8)
129
+ with gr.Row():
130
+ with gr.Column(scale=1.0, min_width=150):
131
+ pychart = gr.Plot(label="Matching Percentage Chart")
132
+ analyse.click(self.matching_percentage, [jobDescription, resume], [perncentage,reason,skills,keywords,pychart])
133
+
134
+ app.launch()
135
+
136
+ resume=ResumeAnalyser()
137
+ resume.gradio_interface()