hydai commited on
Commit
614f3c6
·
1 Parent(s): 8b2b677

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +232 -0
app.py ADDED
@@ -0,0 +1,232 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import openai
3
+ import streamlit as st
4
+ import fitz
5
+
6
+ # environment setup
7
+ #key=st.text_input('Please input your OpenAI key')
8
+ key='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'
9
+ openai.api_key=key
10
+
11
+
12
+ def prompt1(company,position,round,intervier_level):
13
+ prompt=f"""
14
+ I want you to act as a {intervier_level} for {round} interviews on {company} company for the position of {position}. You'll suggest the characteristics of this job interview and the characteristics of the {company}'s interview.
15
+ The return format should bullet point be like this:
16
+ Characteristics of this job interview:
17
+ - name: detail explanation
18
+ Characteristics of {company}:
19
+ - name: detail explanation
20
+ """
21
+ return prompt
22
+
23
+ def followup1(company,position,round,bullet_point):
24
+ prompt=f"""
25
+ Can you talk the detail about {bullet_point} for {round} interviews on {company} company for the position of {position}?
26
+ The return format should bullet point be like this:
27
+ - name: detail explanation
28
+ """
29
+ return prompt
30
+
31
+ def prompt2(position):
32
+ prompt=f"""
33
+ I want you to act as a talent recruiter for the position of {position}'s interviews. You'll suggest the characteristics of this job interview for both behavior requirement and technical requirement.
34
+ The return format should bullet point be like this:
35
+ Characteristics of this behavior requirement:
36
+ - name: detail explanation
37
+ Characteristics of technical requirement:
38
+ - name: detail explanation
39
+ """
40
+ return prompt
41
+
42
+ def followup2(position,bullet_point):
43
+ prompt=f"""
44
+ Can you talk the detail about {bullet_point} for the interview of {position}?
45
+ The return format should bullet point be like this:
46
+ - name: detail impovement advice
47
+ """
48
+ return prompt
49
+
50
+ def prompt3(position,resume,dis_num,ad_num):
51
+ prompt=f"""
52
+ I want you to act as a talent recruiter for hiring {position}. I will give you a resume and you'll suggest what are {dis_num}+ disadvantages and {ad_num}+ advantages of the {position} position. Please remember, the return should be highly related to the {position} position.
53
+ The return format should bullet point be like this:
54
+ Disadvatage:
55
+ - name: Suggestions for improvements to make the resume more appropriate for the {position} position and link to specific sentences on the resume.
56
+ Advantage:
57
+ - name: use one sentence to explain why it is advantageous for the {position} position.
58
+
59
+ Here is the resume:
60
+ {resume}.
61
+ """
62
+ return prompt
63
+
64
+ def followup3(position,resume,bullet_point):
65
+ prompt=f"""
66
+ Can you talk the detail about {bullet_point} for the position of {position} based on {resume}?
67
+ The return format should bullet point be like this:
68
+ - name: detail impovement advice
69
+ """
70
+ return prompt
71
+
72
+
73
+ def ask(prompt):
74
+ rsp = openai.ChatCompletion.create(
75
+ model="gpt-3.5-turbo",
76
+ messages=[
77
+ {"role": "system", "content": prompt},
78
+ ]
79
+ )
80
+
81
+ output=rsp.choices[0].message.content
82
+ return output
83
+
84
+ ####################
85
+
86
+ st.title('InterviewPrepGPT')
87
+ st.subheader('A tool using to help people prepare their interview by using gpt3.5')
88
+
89
+
90
+
91
+ option = st.selectbox(
92
+ 'How would you like to prepare for the interview?',
93
+ ('Prepare for a specific interview',
94
+ 'Understand the requirement of a specific position',
95
+ 'Analyze resume',
96
+ ))
97
+
98
+ if "submit" not in st.session_state:
99
+ st.session_state["submit"] = False
100
+
101
+ st.write('')
102
+ ###### option 1
103
+ if option=='Prepare for a specific interview':
104
+ col1, col2= st.columns(2)
105
+ with col1:
106
+ company=st.text_input('Input your company','Amazon')
107
+ with col2:
108
+ position=st.text_input('Input your position','Data engineer')
109
+
110
+ col3, col4 = st.columns(2)
111
+ with col3:
112
+ intervier_level=st.text_input('Input your interviewer level: ','Talent Recuriter')
113
+ with col4:
114
+ round=st.radio('Select your round: ',('Phone Screen','Behavior Interview','Technical Interview', 'General'))
115
+ if round=='General':
116
+ round=''
117
+
118
+ st.write('Click button again if you want to regenerate a new ansewer.')
119
+ submit_button=st.button('Submit')
120
+
121
+ if st.session_state.get('button') != True:
122
+ st.session_state['button'] = submit_button
123
+ if st.session_state['button'] == True:
124
+ prompt=prompt1(company,position,round,intervier_level)
125
+ output=ask(prompt)
126
+ st.write(output)
127
+
128
+ followup_time=0
129
+ followup=''
130
+ while True:
131
+ output_list=output.split('\n')
132
+ indexes = [i for i, word in enumerate(output_list) if '- ' in word]
133
+ new_list = [output_list[i] for i in indexes]
134
+ Cq=[i.split(':')[0].strip('- ') for i in new_list]
135
+ Cq = ['None']+ Cq
136
+
137
+ followup_radio = st.radio('I want to follow up:', tuple(Cq),key='0')
138
+ if followup_radio:
139
+ followup_time +=1
140
+ if followup_radio == 'None':
141
+ break
142
+ else:
143
+ if followup_radio != 'None':
144
+ followup = followup1(company, position, round, followup_radio)
145
+ output = ask(followup)
146
+ st.write(output)
147
+ if followup_time>5:
148
+ break
149
+
150
+
151
+ ###### option 2
152
+ if option =='Understand the requirement of a specific position':
153
+ position=st.text_input('Input your position','Data engineer')
154
+
155
+ st.write('Click button again if you want to regenerate a new ansewer.')
156
+
157
+ submit=st.checkbox('submit')
158
+
159
+ if submit:
160
+ prompt=prompt2(position)
161
+ output=ask(prompt)
162
+ st.write(output)
163
+
164
+ followup=''
165
+ output_list=output.split('\n')
166
+ indexes = [i for i, word in enumerate(output_list) if '- ' in word]
167
+ new_list = [output_list[i] for i in indexes]
168
+ Cq=[i.split(':')[0].strip('- ') for i in new_list]
169
+ Cq = ['None']+ Cq
170
+
171
+
172
+ followup_radio = st.radio('I want to follow up:', tuple(Cq))
173
+ if followup_radio!='None':
174
+ followup = followup2(position,followup_radio)
175
+ op = ask(followup)
176
+ st.write(op)
177
+
178
+
179
+ ###### option 3
180
+
181
+ if option =='Analyze resume':
182
+
183
+ uploaded_file = st.file_uploader("Upload your resume", type=["pdf"])
184
+ if uploaded_file:
185
+
186
+ if "submit" not in st.session_state:
187
+ st.session_state["submit"] = False
188
+
189
+ doc = fitz.open(stream=uploaded_file.read(), filetype="pdf")
190
+ resume = ""
191
+ for page in doc:
192
+ resume += page.get_text()
193
+
194
+ col31, col32,col33= st.columns(3)
195
+ with col31:
196
+ position=st.text_input('Input your position')
197
+ with col32:
198
+ dis_num=st.text_input('Input your dis_num')
199
+ with col33:
200
+ ad_num=st.text_input('Input your ad_num')
201
+
202
+ st.write('Click button again if you want to regenerate a new ansewer.')
203
+ submit_button=st.button('Submit')
204
+
205
+ if st.session_state.get('button') != True:
206
+ st.session_state['button'] = submit_button
207
+ if st.session_state['button'] == True:
208
+ prompt=prompt3(position,resume,dis_num,ad_num)
209
+ output=ask(prompt)
210
+ st.write(output)
211
+
212
+ followup_time=0
213
+ while True:
214
+ output_list=output.split('\n')
215
+ output_list= [element for element in output_list if element != '']
216
+
217
+ ind = [i for i, word in enumerate(output_list) if 'Advantage:' in word]
218
+ Cdis_list=output_list[1:int(dis_num)+1]
219
+ Cdis=[i.split(':')[0].strip('- ') for i in Cdis_list]
220
+ Cdis = ['None']+ Cdis
221
+
222
+ followup_radio = st.radio('I want to follow up:', tuple(Cdis),key=followup_time)
223
+ followup_time +=1
224
+ if followup_radio == 'None':
225
+ break
226
+ else:
227
+ followup = followup3(position,resume,followup_radio)
228
+ output = ask(followup)
229
+ st.write(output)
230
+ if followup_time>4:
231
+ break
232
+