File size: 6,955 Bytes
cb65bf0
 
 
 
 
 
4d7ad53
2a1c09f
cb65bf0
 
fdfd375
cb65bf0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212cc73
 
4d7ad53
212cc73
 
 
 
cb65bf0
 
 
212cc73
 
 
 
 
4d7ad53
 
212cc73
cb65bf0
212cc73
cb65bf0
 
 
212cc73
cb65bf0
 
 
 
 
 
 
 
 
 
 
 
 
 
212cc73
cb65bf0
 
 
 
212cc73
cb65bf0
 
212cc73
 
 
cb65bf0
 
 
212cc73
cb65bf0
 
212cc73
cb65bf0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212cc73
 
cb65bf0
 
4e18293
7ab492a
 
cb65bf0
 
1a5115e
 
6c4c5de
cb65bf0
 
212cc73
 
 
 
cb65bf0
212cc73
 
 
 
cb65bf0
 
 
 
 
 
 
 
 
 
 
 
 
 
212cc73
 
cb65bf0
 
f1efac8
cb65bf0
 
 
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import gradio as gr
import PyPDF2
import os
import openai
import re
import plotly.graph_objects as go
from openai import AzureOpenAI

class ResumeAnalyser:
  def __init__(self):
      self.client = AzureOpenAI(azure_deployment = "gpt-4o") 
  def extract_text_from_file(self,file_path):
      # Get the file extension
      file_extension = os.path.splitext(file_path)[1]

      if file_extension == '.pdf':
          with open(file_path, 'rb') as file:
              # Create a PDF file reader object
              reader = PyPDF2.PdfFileReader(file)

              # Create an empty string to hold the extracted text
              extracted_text = ""

              # Loop through each page in the PDF and extract the text
              for page_number in range(reader.getNumPages()):
                  page = reader.getPage(page_number)
                  extracted_text += page.extractText()
          return extracted_text

      elif file_extension == '.txt':
          with open(file_path, 'r') as file:
              # Just read the entire contents of the text file
              return file.read()

      else:
          return "Unsupported file type"

  def responce_from_ai(self,textjd, textcv):
      job_description = self.extract_text_from_file(textjd)
      resume = self.extract_text_from_file(textcv)
        
      conversation = [
          {"role": "system", "content": "You are a Reason Analyser"},
          {"role": "user", "content": f"""
  Given the job description and the resume, access the matching percentage to 100 and if 100 percentage not matched mention the remaining percentage with reason.if doesn't match return 0. **Job Description:**{job_description}**Resume:**{resume}
  **Detailed Analysis:**
                  the result should be in this format:
                  Matched Percentage: [matching percentage].
                  Reason            : [give me a Reason (shortly in passage) and keys from job_description and resume get this matched percentage.].
                  Skills To Improve : [give me a the skills How to improve and get 100 percentage job description matching (shortly in passage).].
                  Keywords          : [give me a matched key words from {job_description} and {resume}].
                  """}
      ]
      response = self.client.chat.completions.create(
          model="ChatGPT",
          messages=conversation,
          temperature=0,
          max_tokens=500,
          n=1,
          stop=None,
      )
      generated_text = response.choices[0].message.content
      print(generated_text)
      return generated_text


  def matching_percentage(self,job_description_path, resume_path):
      job_description_path = job_description_path.name
      resume_path = resume_path.name

      generated_text = self.responce_from_ai(job_description_path, resume_path)

      result = generated_text

      lines = result.split('\n')
        
      matched_percentage = 0
      matched_percentage_txt = None
      reason = None
      skills_to_improve = None
      keywords = None

      for line in lines:
          if line.startswith('Matched Percentage:'):
              matched_percentage = re.search(r'\d+', line)
              if matched_percentage:
                  matched_percentage = int(matched_percentage.group())
                  matched_percentage_txt = (f"Matched Percentage: {matched_percentage}%")
          elif line.startswith('Reason'):
              reason = line.split(':')[1].strip()
              print(reason)
          elif line.startswith('Skills To Improve'):
              skills_to_improve = line.split(':')[1].strip()
              print(skills_to_improve)
          elif line.startswith('Keywords'):
              keywords = line.split(':')[1].strip()


      # Extract the matched percentage using regular expression
      # match1 = re.search(r"Matched Percentage: (\d+)%", matched_percentage)
      # matched_Percentage = int(match1.group(1))

      # Creating a pie chart with plotly
      labels = ['Matched', 'Remaining']
      values = [matched_percentage, 100 - matched_percentage]

      fig = go.Figure(data=[go.Pie(labels=labels, values=values)])
      # fig.update_layout(title='Matched Percentage')


      return matched_percentage_txt,reason, skills_to_improve, keywords,fig

  def filename(self,uploadbutton):
      return uploadbutton.name

  def gradio_interface(self):
      with gr.Blocks(css="style.css",theme="freddyaboulton/test-blue") as app:
            # gr.HTML("""<img class="leftimage" align="left" src="https://lh5.googleusercontent.com/Oe_QQsjdEEDWZtgR5v8DHJe3aHP5rOj4FkfpCbo6CELP6xzoHh7N_nYV62cZhMQcLNlvR8xaFq7nMd4V1W-gKeIZ67QAECE9m6pRuRJah9MCdHg5N1q3oJ-4rOoxTc8ZdA=w1280" alt="Image" width="210" height="210">
            #           <img class="rightimage" align="right" src="https://companieslogo.com/img/orig/RAND.AS_BIG-0f1935a4.png?t=1651813778" alt="Image" width="210" height="210">""")

            with gr.Row():
                gr.HTML("""<center class="darkblue" text-align:center;padding:30px;'><center>
                <center><h1 class ="center" style="color:#fff">ADOPLE AI</h1></center>
                <br><center><h1 style="color:#fff">Resume Analyser</h1></center>""")   
            with gr.Row():
              with gr.Column(scale=0.45, min_width=150, ):
                file_jd = gr.File()
                jobDescription = gr.UploadButton(
                    "Browse File",file_types=[".txt", ".pdf", ".doc", ".docx",".json",".csv"],
                    elem_classes="filenameshow")
              with gr.Column(scale=0.45, min_width=150):
                file_resume = gr.File()
                resume = gr.UploadButton(
                    "Browse File",file_types=[".txt", ".pdf", ".doc", ".docx",".json",".csv"],
                    elem_classes="filenameshow")
              with gr.Column(scale=0.10, min_width=150):
                analyse = gr.Button("Analyse")
            with gr.Row():
              with gr.Column(scale=1.0, min_width=150):
                perncentage = gr.Textbox(label="Matching Percentage",lines=8)
              with gr.Column(scale=1.0, min_width=150):
                reason = gr.Textbox(label="Matching Reason",lines=8)
              with gr.Column(scale=1.0, min_width=150):
                skills = gr.Textbox(label="Skills To Improve",lines=8)
              with gr.Column(scale=1.0, min_width=150):
                keywords = gr.Textbox(label="Matched Keywords",lines=8)
            with gr.Row():
              with gr.Column(scale=1.0, min_width=150):
                pychart = gr.Plot(label="Matching Percentage Chart")
            jobDescription.upload(self.filename,jobDescription,file_jd)
            resume.upload(self.filename,resume,file_resume)
            analyse.click(self.matching_percentage, [jobDescription, resume], [perncentage,reason,skills,keywords,pychart])

      app.launch()

resume=ResumeAnalyser()
resume.gradio_interface()