Spaces:
Runtime error
Runtime error
Karthikeyan
commited on
Commit
•
e5453a8
1
Parent(s):
32524af
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
class QuestionsGenarator:
|
2 |
+
def __init__(self):
|
3 |
+
openai.api_key = "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"
|
4 |
+
|
5 |
+
def extract_text_from_file(self,file_path):
|
6 |
+
# Get the file extension
|
7 |
+
file_extension = os.path.splitext(file_path)[1]
|
8 |
+
|
9 |
+
if file_extension == '.pdf':
|
10 |
+
with open(file_path, 'rb') as file:
|
11 |
+
# Create a PDF file reader object
|
12 |
+
reader = PyPDF2.PdfFileReader(file)
|
13 |
+
|
14 |
+
# Create an empty string to hold the extracted text
|
15 |
+
extracted_text = ""
|
16 |
+
|
17 |
+
# Loop through each page in the PDF and extract the text
|
18 |
+
for page_number in range(reader.getNumPages()):
|
19 |
+
page = reader.getPage(page_number)
|
20 |
+
extracted_text += page.extractText()
|
21 |
+
return extracted_text
|
22 |
+
|
23 |
+
elif file_extension == '.txt':
|
24 |
+
with open(file_path, 'r') as file:
|
25 |
+
# Just read the entire contents of the text file
|
26 |
+
return file.read()
|
27 |
+
|
28 |
+
elif file_extension == '.docx':
|
29 |
+
doc = docx.Document(file_path)
|
30 |
+
text = []
|
31 |
+
for paragraph in doc.paragraphs:
|
32 |
+
text.append(paragraph.text)
|
33 |
+
return '\n'.join(text)
|
34 |
+
|
35 |
+
else:
|
36 |
+
return "Unsupported file type"
|
37 |
+
|
38 |
+
def response(self,job_description_path):
|
39 |
+
job_description_path = job_description_path.name
|
40 |
+
resume = self.extract_text_from_file(job_description_path)
|
41 |
+
|
42 |
+
|
43 |
+
# Define the prompt or input for the model
|
44 |
+
prompt = f"""Find Education Gaps in given resume. Find Skills in resume.
|
45 |
+
```{resume}```
|
46 |
+
"""
|
47 |
+
|
48 |
+
# Generate a response from the GPT-3 model
|
49 |
+
response = openai.Completion.create(
|
50 |
+
engine='text-davinci-003', # Choose the GPT-3 engine you want to use
|
51 |
+
prompt=prompt,
|
52 |
+
max_tokens=100, # Set the maximum number of tokens in the generated response
|
53 |
+
temperature=0, # Controls the randomness of the output. Higher values = more random, lower values = more focused
|
54 |
+
n=1, # Generate a single response
|
55 |
+
stop=None, # Specify an optional stop sequence to limit the length of the response
|
56 |
+
)
|
57 |
+
|
58 |
+
# Extract the generated text from the API response
|
59 |
+
generated_text = response.choices[0].text.strip()
|
60 |
+
|
61 |
+
return generated_text
|
62 |
+
|
63 |
+
def gradio_interface(self):
|
64 |
+
with gr.Blocks(css="style.css",theme=gr.themes.Soft()) as app:
|
65 |
+
gr.HTML("""<img class="leftimage" align="left" src="https://templates.images.credential.net/1612472097627370951721412474196.png" alt="Image" width="210" height="210">
|
66 |
+
<img class="rightimage" align="right" src="https://companieslogo.com/img/orig/RAND.AS_BIG-0f1935a4.png?t=1651813778" alt="Image" width="210" height="210">""")
|
67 |
+
|
68 |
+
with gr.Row(elem_id="col-container"):
|
69 |
+
with gr.Column():
|
70 |
+
gr.HTML("<br>")
|
71 |
+
gr.HTML(
|
72 |
+
"""<h1 style="text-align:center; color:"white">Randstad Resume Analyzer to find Skills and Education Gaps</h1> """
|
73 |
+
)
|
74 |
+
with gr.Column():
|
75 |
+
jobDescription = gr.File(label="Resume")
|
76 |
+
|
77 |
+
with gr.Column():
|
78 |
+
analyse = gr.Button("Analyze Resume")
|
79 |
+
|
80 |
+
with gr.Column():
|
81 |
+
result = gr.Textbox(label="Skills and Education Gaps",lines=8)
|
82 |
+
|
83 |
+
analyse.click(self.response, [jobDescription], result)
|
84 |
+
|
85 |
+
app.launch()
|
86 |
+
|
87 |
+
resume=QuestionsGenarator()
|
88 |
+
resume.gradio_interface()
|