Karthikeyan commited on
Commit
0d938ae
1 Parent(s): dda36eb

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +95 -0
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 QuestionsGenerator:
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,job_description_path):
45
+ job_description_path = job_description_path.name
46
+ job_description = self.extract_text_from_file(job_description_path)
47
+
48
+
49
+ # Define the prompt or input for the model
50
+ prompt = f"""Generate interview questions for screening following job_description delimitted by triple backticks. Generate atmost ten questions.
51
+ ```{job_description}```
52
+ """
53
+
54
+ # Generate a response from the GPT-3 model
55
+ response = openai.Completion.create(
56
+ engine='text-davinci-003', # Choose the GPT-3 engine you want to use
57
+ prompt=prompt,
58
+ max_tokens=200, # Set the maximum number of tokens in the generated response
59
+ temperature=0, # Controls the randomness of the output. Higher values = more random, lower values = more focused
60
+ n=1, # Generate a single response
61
+ stop=None, # Specify an optional stop sequence to limit the length of the response
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">Randstad Questions For Screening</h1> """
79
+ )
80
+ gr.HTML("<br>")
81
+ with gr.Column():
82
+ jobDescription = gr.File(label="Job Description")
83
+
84
+ with gr.Column():
85
+ analyse = gr.Button("Generate")
86
+
87
+ with gr.Column():
88
+ result = gr.Textbox(label="Questions For Screening",lines=8)
89
+
90
+ analyse.click(self.response, [jobDescription], result)
91
+
92
+ app.launch()
93
+
94
+ ques = QuestionsGenerator()
95
+ ques.gradio_interface()