KarthickAdopleAI commited on
Commit
212cc73
·
verified ·
1 Parent(s): 515df88

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -20
app.py CHANGED
@@ -5,6 +5,7 @@ import openai
5
  import re
6
  import plotly.graph_objects as go
7
  from openai import OpenAI
 
8
  class ResumeAnalyser:
9
  def __init__(self):
10
  pass
@@ -35,26 +36,30 @@ class ResumeAnalyser:
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
  client = OpenAI()
41
- response = client.chat.completions.create(
42
- engine="gpt-3.5-turbo",
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 : [Mention Reason and keys from job_description and resume get this matched percentage.].
49
- Skills To Improve : [Mention the skills How to improve and get 100 percentage job description 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
 
@@ -69,22 +74,24 @@ class ResumeAnalyser:
69
 
70
  lines = result.split('\n')
71
 
72
- matched_percentage = None
73
  matched_percentage_txt = None
74
  reason = None
75
  skills_to_improve = None
76
  keywords = None
77
-
78
  for line in lines:
79
  if line.startswith('Matched Percentage:'):
80
- match = re.search(r"Matched Percentage: (\d+)%", line)
81
- if match:
82
- matched_percentage = int(match.group(1))
83
  matched_percentage_txt = (f"Matched Percentage: {matched_percentage}%")
84
  elif line.startswith('Reason'):
85
  reason = line.split(':')[1].strip()
 
86
  elif line.startswith('Skills To Improve'):
87
  skills_to_improve = line.split(':')[1].strip()
 
88
  elif line.startswith('Keywords'):
89
  keywords = line.split(':')[1].strip()
90
 
@@ -103,6 +110,8 @@ class ResumeAnalyser:
103
 
104
  return matched_percentage_txt,reason, skills_to_improve, keywords,fig
105
 
 
 
106
 
107
  def gradio_interface(self):
108
  with gr.Blocks(css="style.css",theme="freddyaboulton/test-blue") as app:
@@ -115,9 +124,15 @@ class ResumeAnalyser:
115
  <br><center><h1 style="color:#fff">Resume Analyser</h1></center>""")
116
  with gr.Row():
117
  with gr.Column(scale=0.45, min_width=150, ):
118
- jobDescription = gr.File(label="Job Description")
 
 
 
119
  with gr.Column(scale=0.45, min_width=150):
120
- resume = gr.File(label="Resume")
 
 
 
121
  with gr.Column(scale=0.10, min_width=150):
122
  analyse = gr.Button("Analyse")
123
  with gr.Row():
@@ -132,9 +147,11 @@ class ResumeAnalyser:
132
  with gr.Row():
133
  with gr.Column(scale=1.0, min_width=150):
134
  pychart = gr.Plot(label="Matching Percentage Chart")
 
 
135
  analyse.click(self.matching_percentage, [jobDescription, resume], [perncentage,reason,skills,keywords,pychart])
136
 
137
- app.launch()
138
 
139
  resume=ResumeAnalyser()
140
  resume.gradio_interface()
 
5
  import re
6
  import plotly.graph_objects as go
7
  from openai import OpenAI
8
+ os.environ["OPENAI_API_KEY"] = "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"
9
  class ResumeAnalyser:
10
  def __init__(self):
11
  pass
 
36
  return "Unsupported file type"
37
 
38
  def responce_from_ai(self,textjd, textcv):
39
+ job_description = self.extract_text_from_file(textjd)
40
+ resume = self.extract_text_from_file(textcv)
41
  client = OpenAI()
42
+ conversation = [
43
+ {"role": "system", "content": "You are a Reason Analyser"},
44
+ {"role": "user", "content": f"""
45
+ 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}
46
  **Detailed Analysis:**
47
  the result should be in this format:
48
  Matched Percentage: [matching percentage].
49
+ Reason : [give me a Reason (shortly in passage) and keys from job_description and resume get this matched percentage.].
50
+ Skills To Improve : [give me a the skills How to improve and get 100 percentage job description matching (shortly in passage).].
51
+ Keywords : [give me a matched key words from {job_description} and {resume}].
52
+ """}
53
+ ]
54
+ response = client.chat.completions.create(
55
+ model="gpt-3.5-turbo",
56
+ messages=conversation,
57
  temperature=0,
58
+ max_tokens=500,
59
  n=1,
60
  stop=None,
61
  )
62
+ generated_text = response.choices[0].message.content
63
  print(generated_text)
64
  return generated_text
65
 
 
74
 
75
  lines = result.split('\n')
76
 
77
+ matched_percentage = 0
78
  matched_percentage_txt = None
79
  reason = None
80
  skills_to_improve = None
81
  keywords = None
82
+
83
  for line in lines:
84
  if line.startswith('Matched Percentage:'):
85
+ matched_percentage = re.search(r'\d+', line)
86
+ if matched_percentage:
87
+ matched_percentage = int(matched_percentage.group())
88
  matched_percentage_txt = (f"Matched Percentage: {matched_percentage}%")
89
  elif line.startswith('Reason'):
90
  reason = line.split(':')[1].strip()
91
+ print(reason)
92
  elif line.startswith('Skills To Improve'):
93
  skills_to_improve = line.split(':')[1].strip()
94
+ print(skills_to_improve)
95
  elif line.startswith('Keywords'):
96
  keywords = line.split(':')[1].strip()
97
 
 
110
 
111
  return matched_percentage_txt,reason, skills_to_improve, keywords,fig
112
 
113
+ def filename(self,uploadbutton):
114
+ return uploadbutton.name
115
 
116
  def gradio_interface(self):
117
  with gr.Blocks(css="style.css",theme="freddyaboulton/test-blue") as app:
 
124
  <br><center><h1 style="color:#fff">Resume Analyser</h1></center>""")
125
  with gr.Row():
126
  with gr.Column(scale=0.45, min_width=150, ):
127
+ file_jd = gr.File()
128
+ jobDescription = gr.UploadButton(
129
+ "Browse File",file_types=[".txt", ".pdf", ".doc", ".docx",".json",".csv"],
130
+ elem_classes="filenameshow")
131
  with gr.Column(scale=0.45, min_width=150):
132
+ file_resume = gr.File()
133
+ resume = gr.UploadButton(
134
+ "Browse File",file_types=[".txt", ".pdf", ".doc", ".docx",".json",".csv"],
135
+ elem_classes="filenameshow")
136
  with gr.Column(scale=0.10, min_width=150):
137
  analyse = gr.Button("Analyse")
138
  with gr.Row():
 
147
  with gr.Row():
148
  with gr.Column(scale=1.0, min_width=150):
149
  pychart = gr.Plot(label="Matching Percentage Chart")
150
+ jobDescription.upload(self.filename,jobDescription,file_jd)
151
+ resume.upload(self.filename,resume,file_resume)
152
  analyse.click(self.matching_percentage, [jobDescription, resume], [perncentage,reason,skills,keywords,pychart])
153
 
154
+ app.launch(debug=True)
155
 
156
  resume=ResumeAnalyser()
157
  resume.gradio_interface()