File size: 11,343 Bytes
77de8f5
 
 
 
 
 
c6a6642
77de8f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f83ca37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77de8f5
 
 
 
b833576
8940745
d5a07b7
7e9b9e4
d5a07b7
 
 
7e9b9e4
f83ca37
 
 
d5a07b7
daab587
f83ca37
 
d5a07b7
 
f83ca37
 
d5a07b7
 
f83ca37
 
d5a07b7
 
f83ca37
d5a07b7
 
 
 
 
06ad49c
8940745
d5a07b7
cea1d7b
c6a6642
cea1d7b
c6a6642
d5a07b7
8940745
f83ca37
59fed38
f83ca37
59fed38
f83ca37
511f751
f83ca37
51893e1
cea1d7b
51893e1
cea1d7b
511f751
f83ca37
511f751
f83ca37
 
 
 
 
 
77de8f5
 
 
 
 
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
import os
import openai
import PyPDF2
import gradio as gr
import docx
import re


class Resume_Overall:
    def __init__(self):
        pass

    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()

        elif file_extension == '.docx':
              doc = docx.Document(file_path)
              text = []
              for paragraph in doc.paragraphs:
                  text.append(paragraph.text)
              return '\n'.join(text)

        else:
            return "Unsupported file type"

    def course_response(self,resume_path):
        resume_path = resume_path.name
        resume = self.extract_text_from_file(resume_path)


        # Define the prompt or input for the model
        prompt = f"""Analyze the resume to generate online courses with website links to improve skills following resume delimitted by triple backticks. Generate atmost five courses.
                     result format should be:
                     course:[course].
                     website link:[website link]
                     ```{resume}```
                  """

        # Generate a response from the GPT-3 model
        response = openai.Completion.create(
            engine='text-davinci-003',
            prompt=prompt,
            max_tokens=200,
            temperature=0,
            n=1,
            stop=None,
        )

        # Extract the generated text from the API response
        generated_text = response.choices[0].text.strip()

        return generated_text
    def summary_response(self,resume_path):
        resume_path = resume_path.name
        resume = self.extract_text_from_file(resume_path)


        # Define the prompt or input for the model
        prompt = f"""Analyze the resume to write the summary for following resume delimitted by triple backticks.
                     ```{resume}```
                  """

        # Generate a response from the GPT-3 model
        response = openai.Completion.create(
            engine='text-davinci-003',
            prompt=prompt,
            max_tokens=200,
            temperature=0,
            n=1,
            stop=None,
        )

        # Extract the generated text from the API response
        generated_text = response.choices[0].text.strip()

        return generated_text
  

    def skill_response(self,job_description_path):
        job_description_path = job_description_path.name
        resume = self.extract_text_from_file(job_description_path)


        # Define the prompt or input for the model
        prompt = f"""Find Education Gaps in given resume. Find Skills in resume.
                      ```{resume}```
                  """

        # Generate a response from the GPT-3 model
        response = openai.Completion.create(
            engine='text-davinci-003',  # Choose the GPT-3 engine you want to use
            prompt=prompt,
            max_tokens=100,  # Set the maximum number of tokens in the generated response
            temperature=0,  # Controls the randomness of the output. Higher values = more random, lower values = more focused
            n=1,  # Generate a single response
            stop=None,  # Specify an optional stop sequence to limit the length of the response
        )

        # Extract the generated text from the API response
        generated_text = response.choices[0].text.strip()

        return generated_text

    def _generate_job_list(self, resume: str) -> str:
        prompt = f"List out perfect job roles for based on resume informations:{resume}"
        response = openai.Completion.create(
            engine='text-davinci-003',
            prompt=prompt,
            max_tokens=100,
            temperature=0,
            n=1,
            stop=None,
        )
        generated_text = response.choices[0].text.strip()
        return generated_text


    def job_list_interface(self, file) -> str:
        resume_text = self.extract_text_from_file(file.name)

        job_list = self._generate_job_list(resume_text)
        return job_list

    def generate_job_description(self, role, experience):
        # Generate a response from the GPT-3 model

        prompt = f"""Your task is generate Job description for this {role} with {experience} years of experience.
                    Job Description Must have
                    1. Job Title
                    2. Job Summary : [200 words]
                    3. Responsibilities : Five Responsibilities in five lines
                    4. Required Skills : Six Skills
                    5. Qualifications
                  These topics must have in that Generated Job Description.
                  """
        response = openai.Completion.create(
            engine='text-davinci-003',  # Choose the GPT-3 engine you want to use
            prompt=prompt,
            max_tokens=500,  # Set the maximum number of tokens in the generated response
            temperature=0.5,  # Controls the randomness of the output. Higher values = more random, lower values = more focused
        )

        # Extract the generated text from the API response
        generated_text = response.choices[0].text.strip()

        return generated_text  
        
    def response(self,job_description_path):
        job_description_path = job_description_path.name
        job_description = self.extract_text_from_file(job_description_path)


        # Define the prompt or input for the model
        prompt = f"""Generate interview questions for screening following job_description delimitted by triple backticks. Generate atmost ten questions.
                     ```{job_description}```
                  """

        # Generate a response from the GPT-3 model
        response = openai.Completion.create(
            engine='text-davinci-003',  # Choose the GPT-3 engine you want to use
            prompt=prompt,
            max_tokens=200,  # Set the maximum number of tokens in the generated response
            temperature=0,  # Controls the randomness of the output. Higher values = more random, lower values = more focused
            n=1,  # Generate a single response
            stop=None,  # Specify an optional stop sequence to limit the length of the response
        )

        # Extract the generated text from the API response
        generated_text = response.choices[0].text.strip()

        return generated_text 
        
    def show_file(self,file_path):
      return file_path.name

    def launch_gradio_interface(self, share: bool = True):
        with gr.Blocks(css="style.css",theme='freddyaboulton/test-blue') as app:
            with gr.Tab("Resume"):
                with gr.Row():
                    with gr.Column(elem_id="col-container",scale=0.60):
                        file_output = gr.File(elem_classes="filenameshow")
                        upload_button = gr.UploadButton(
                            "Browse File",file_types=[".txt", ".pdf", ".doc", ".docx",".json",".csv"],
                            elem_classes="uploadbutton",scale=0.60)
  
                with gr.TabItem("Designation"):
                    with gr.Column(elem_id = "col-container",scale=0.80):
                        btn = gr.Button(value="Submit")
                        output_text = gr.Textbox(label="Designation List",lines=8)
                with gr.TabItem("Summarized"):  
                    with gr.Column(elem_id = "col-container",scale=0.80):
                        analyse = gr.Button("Analyze")
                        summary_result = gr.Textbox(label="Summarized",lines=8)      
                with gr.TabItem("Skills and Education Gaps"):  
                    with gr.Column(elem_id = "col-container",scale=0.80):
                        analyse_resume = gr.Button("Analyze Resume")
                        result = gr.Textbox(label="Skills and Education Gaps",lines=8)
                with gr.TabItem("Course"): 
                    with gr.Column(elem_id = "col-container",scale=0.80):
                        course_analyse = gr.Button("Find Courses")
                        course_result = gr.Textbox(label="Suggested Cources",lines=8)
        
                upload_button.upload(self.show_file,upload_button,file_output)
                course_analyse.click(self.course_response, [upload_button], course_result)
                analyse_resume.click(self.skill_response, [upload_button], result)
                btn.click(self.job_list_interface, upload_button, output_text)
                analyse.click(self.summary_response, [upload_button], summary_result)
                
            with gr.Tab("Job Description"):
                with gr.Row():
                    with gr.Column(elem_id="col-container",scale=0.60):
                        file_output1 = gr.File(elem_classes="filenameshow")
                    with gr.Column(elem_id="col-container",scale=0.60):    
                        upload_button1 = gr.UploadButton(
                            "Browse File",file_types=[".txt", ".pdf", ".doc", ".docx",".json",".csv"],
                            elem_classes="uploadbutton")  
                with gr.TabItem("Screening Question"):        
                    with gr.Row(elem_id="col-container"):        
                            jd_btn = gr.Button(value="Submit")
                    with gr.Row(elem_id="col-container"):      
                            output_text1 = gr.Textbox(label="Screening Question") 
                with gr.TabItem("Generate JD"):    
                    with gr.Row():
                        with gr.Column(elem_id="col-container", scale=0.60):
                             rolls = gr.Textbox(label="Role",scale=0.60)
                        with gr.Column(elem_id="col-container", scale=0.60):    
                             experience = gr.Textbox(label="Experience",scale=0.60)
                    with gr.Row(elem_id="col-container"):
                        get_jd_btn = gr.Button("Generate JD")
                    with gr.Row(elem_id="col-container"):
                        result_jd = gr.Textbox(label="Job Description",lines=8)
                            
                get_jd_btn.click(self.generate_job_description, [rolls,experience], result_jd)      
                upload_button1.upload(self.show_file,upload_button1,file_output1)        
                jd_btn.click(self.response,[upload_button1], output_text1)
                
        app.launch(debug=True)

if __name__ == "__main__":
    resume_overall = Resume_Overall()
    resume_overall.launch_gradio_interface()