Spaces:
Sleeping
Sleeping
Karthikeyan
commited on
Commit
•
e176162
1
Parent(s):
55ad990
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import openai
|
3 |
+
import PyPDF2
|
4 |
+
import gradio as gr
|
5 |
+
import docx
|
6 |
+
|
7 |
+
class CourseGenarator:
|
8 |
+
def __init__(self):
|
9 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
10 |
+
|
11 |
+
def extract_text_from_file(self,file_path):
|
12 |
+
# Get the file extension
|
13 |
+
file_extension = os.path.splitext(file_path)[1]
|
14 |
+
|
15 |
+
if file_extension == '.pdf':
|
16 |
+
with open(file_path, 'rb') as file:
|
17 |
+
# Create a PDF file reader object
|
18 |
+
reader = PyPDF2.PdfFileReader(file)
|
19 |
+
|
20 |
+
# Create an empty string to hold the extracted text
|
21 |
+
extracted_text = ""
|
22 |
+
|
23 |
+
# Loop through each page in the PDF and extract the text
|
24 |
+
for page_number in range(reader.getNumPages()):
|
25 |
+
page = reader.getPage(page_number)
|
26 |
+
extracted_text += page.extractText()
|
27 |
+
return extracted_text
|
28 |
+
|
29 |
+
elif file_extension == '.txt':
|
30 |
+
with open(file_path, 'r') as file:
|
31 |
+
# Just read the entire contents of the text file
|
32 |
+
return file.read()
|
33 |
+
|
34 |
+
elif file_extension == '.docx':
|
35 |
+
doc = docx.Document(file_path)
|
36 |
+
text = []
|
37 |
+
for paragraph in doc.paragraphs:
|
38 |
+
text.append(paragraph.text)
|
39 |
+
return '\n'.join(text)
|
40 |
+
|
41 |
+
else:
|
42 |
+
return "Unsupported file type"
|
43 |
+
|
44 |
+
def response(self,resume_path):
|
45 |
+
resume_path = resume_path.name
|
46 |
+
resume = self.extract_text_from_file(resume_path)
|
47 |
+
|
48 |
+
|
49 |
+
# Define the prompt or input for the model
|
50 |
+
prompt = f"""Analyze the resume to write the summary for following resume delimitted by triple backticks.
|
51 |
+
```{resume}```
|
52 |
+
"""
|
53 |
+
|
54 |
+
# Generate a response from the GPT-3 model
|
55 |
+
response = openai.Completion.create(
|
56 |
+
engine='text-davinci-003',
|
57 |
+
prompt=prompt,
|
58 |
+
max_tokens=200,
|
59 |
+
temperature=0,
|
60 |
+
n=1,
|
61 |
+
stop=None,
|
62 |
+
)
|
63 |
+
|
64 |
+
# Extract the generated text from the API response
|
65 |
+
generated_text = response.choices[0].text.strip()
|
66 |
+
|
67 |
+
return generated_text
|
68 |
+
|
69 |
+
def gradio_interface(self):
|
70 |
+
with gr.Blocks(css="style.css",theme=gr.themes.Soft()) as app:
|
71 |
+
gr.HTML("""<img class="leftimage" align="left" src="https://templates.images.credential.net/1612472097627370951721412474196.png" alt="Image" width="210" height="210">
|
72 |
+
<img class="rightimage" align="right" src="https://companieslogo.com/img/orig/RAND.AS_BIG-0f1935a4.png?t=1651813778" alt="Image" width="210" height="210">""")
|
73 |
+
|
74 |
+
with gr.Row(elem_id="col-container"):
|
75 |
+
with gr.Column():
|
76 |
+
gr.HTML("<br>")
|
77 |
+
gr.HTML(
|
78 |
+
"""<h1 style="text-align:center; color:"white">Resume Summarizer</h1> """
|
79 |
+
)
|
80 |
+
with gr.Column():
|
81 |
+
resume = gr.File(label="Resume",elem_classes="heightfit")
|
82 |
+
|
83 |
+
with gr.Column():
|
84 |
+
analyse = gr.Button("Analyze")
|
85 |
+
|
86 |
+
with gr.Column():
|
87 |
+
result = gr.Textbox(label="Summarized",lines=8)
|
88 |
+
|
89 |
+
analyse.click(self.response, [resume], result)
|
90 |
+
print(result)
|
91 |
+
|
92 |
+
app.launch()
|
93 |
+
|
94 |
+
ques = CourseGenarator()
|
95 |
+
ques.gradio_interface()
|