robertselvam commited on
Commit
77de8f5
1 Parent(s): c0e1099

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +179 -0
app.py ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import openai
3
+ import PyPDF2
4
+ import gradio as gr
5
+ import docx
6
+ import re
7
+ import plotly.graph_objects as go
8
+
9
+ class Resume_Overall:
10
+ def __init__(self):
11
+ pass
12
+
13
+ def extract_text_from_file(self,file_path):
14
+ # Get the file extension
15
+ file_extension = os.path.splitext(file_path)[1]
16
+
17
+ if file_extension == '.pdf':
18
+ with open(file_path, 'rb') as file:
19
+ # Create a PDF file reader object
20
+ reader = PyPDF2.PdfFileReader(file)
21
+
22
+ # Create an empty string to hold the extracted text
23
+ extracted_text = ""
24
+
25
+ # Loop through each page in the PDF and extract the text
26
+ for page_number in range(reader.getNumPages()):
27
+ page = reader.getPage(page_number)
28
+ extracted_text += page.extractText()
29
+ return extracted_text
30
+
31
+ elif file_extension == '.txt':
32
+ with open(file_path, 'r') as file:
33
+ # Just read the entire contents of the text file
34
+ return file.read()
35
+
36
+ elif file_extension == '.docx':
37
+ doc = docx.Document(file_path)
38
+ text = []
39
+ for paragraph in doc.paragraphs:
40
+ text.append(paragraph.text)
41
+ return '\n'.join(text)
42
+
43
+ else:
44
+ return "Unsupported file type"
45
+
46
+ def course_response(self,resume_path):
47
+ resume_path = resume_path.name
48
+ resume = self.extract_text_from_file(resume_path)
49
+
50
+
51
+ # Define the prompt or input for the model
52
+ 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.
53
+ result format should be:
54
+ course:[course].
55
+ website link:[website link]
56
+ ```{resume}```
57
+ """
58
+
59
+ # Generate a response from the GPT-3 model
60
+ response = openai.Completion.create(
61
+ engine='text-davinci-003',
62
+ prompt=prompt,
63
+ max_tokens=200,
64
+ temperature=0,
65
+ n=1,
66
+ stop=None,
67
+ )
68
+
69
+ # Extract the generated text from the API response
70
+ generated_text = response.choices[0].text.strip()
71
+
72
+ return generated_text
73
+ def summary_response(self,resume_path):
74
+ resume_path = resume_path.name
75
+ resume = self.extract_text_from_file(resume_path)
76
+
77
+
78
+ # Define the prompt or input for the model
79
+ prompt = f"""Analyze the resume to write the summary for following resume delimitted by triple backticks.
80
+ ```{resume}```
81
+ """
82
+
83
+ # Generate a response from the GPT-3 model
84
+ response = openai.Completion.create(
85
+ engine='text-davinci-003',
86
+ prompt=prompt,
87
+ max_tokens=200,
88
+ temperature=0,
89
+ n=1,
90
+ stop=None,
91
+ )
92
+
93
+ # Extract the generated text from the API response
94
+ generated_text = response.choices[0].text.strip()
95
+
96
+ return generated_text
97
+
98
+
99
+ def skill_response(self,job_description_path):
100
+ job_description_path = job_description_path.name
101
+ resume = self.extract_text_from_file(job_description_path)
102
+
103
+
104
+ # Define the prompt or input for the model
105
+ prompt = f"""Find Education Gaps in given resume. Find Skills in resume.
106
+ ```{resume}```
107
+ """
108
+
109
+ # Generate a response from the GPT-3 model
110
+ response = openai.Completion.create(
111
+ engine='text-davinci-003', # Choose the GPT-3 engine you want to use
112
+ prompt=prompt,
113
+ max_tokens=100, # Set the maximum number of tokens in the generated response
114
+ temperature=0, # Controls the randomness of the output. Higher values = more random, lower values = more focused
115
+ n=1, # Generate a single response
116
+ stop=None, # Specify an optional stop sequence to limit the length of the response
117
+ )
118
+
119
+ # Extract the generated text from the API response
120
+ generated_text = response.choices[0].text.strip()
121
+
122
+ return generated_text
123
+
124
+ def _generate_job_list(self, resume: str) -> str:
125
+ prompt = f"List out perfect job roles for based on resume informations:{resume}"
126
+ response = openai.Completion.create(
127
+ engine='text-davinci-003',
128
+ prompt=prompt,
129
+ max_tokens=100,
130
+ temperature=0,
131
+ n=1,
132
+ stop=None,
133
+ )
134
+ generated_text = response.choices[0].text.strip()
135
+ return generated_text
136
+
137
+
138
+ def job_list_interface(self, file) -> str:
139
+ resume_text = self.extract_text_from_file(file.name)
140
+
141
+ job_list = self._generate_job_list(resume_text)
142
+ return job_list
143
+ def show_file(self,file_path):
144
+ return file_path.name
145
+
146
+ def launch_gradio_interface(self, share: bool = True):
147
+ with gr.Blocks(css="style.css",theme='karthikeyan-adople/hudsonhayes-gray') as app:
148
+
149
+ with gr.Row():
150
+ with gr.Column(elem_id="col-container"):
151
+ gr.HTML("""<center><h1>Resume</h1></center>""")
152
+ file_output = gr.File(elem_classes="filenameshow")
153
+ upload_button = gr.UploadButton(
154
+ "Browse File",file_types=[".txt", ".pdf", ".doc", ".docx",".json",".csv"],
155
+ elem_classes="filenameshow")
156
+ with gr.TabItem("Designation"):
157
+ btn = gr.Button(value="Submit")
158
+ output_text = gr.Textbox(label="Designation List")
159
+ with gr.TabItem("Summarized"):
160
+ analyse = gr.Button("Analyze")
161
+ summary_result = gr.Textbox(label="Summarized",lines=8)
162
+ with gr.TabItem("Skills and Education Gaps"):
163
+ analyse_resume = gr.Button("Analyze Resume")
164
+ result = gr.Textbox(label="Skills and Education Gaps",lines=8)
165
+ with gr.TabItem("Course"):
166
+ course_analyse = gr.Button("Find Courses")
167
+ course_result = gr.Textbox(label="Suggested Cources",lines=8)
168
+
169
+ upload_button.upload(self.show_file,upload_button,file_output)
170
+ course_analyse.click(self.course_response, [upload_button], course_result)
171
+ analyse_resume.click(self.skill_response, [upload_button], result)
172
+ btn.click(self.job_list_interface, upload_button, output_text)
173
+ analyse.click(self.summary_response, [upload_button], summary_result)
174
+
175
+ app.launch(debug=True)
176
+
177
+ if __name__ == "__main__":
178
+ resume_overall = Resume_Overall()
179
+ resume_overall.launch_gradio_interface()