ritujadebnath commited on
Commit
7693eec
·
verified ·
1 Parent(s): 954cd3c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +84 -57
app.py CHANGED
@@ -29,6 +29,7 @@ def generate_questions(role, topic, num_questions, difficulty):
29
  return []
30
 
31
  def generate_feedback(responses):
 
32
  prompt = (
33
  "Evaluate the following interview responses. For each response, provide: \n"
34
  "1. Normal feedback.\n"
@@ -92,6 +93,7 @@ def save_performance(role, topic, difficulty, feedback):
92
  def schedule_mock_interview(date_time):
93
  return f"Mock interview scheduled for {date_time}"
94
 
 
95
  def analyze_performance():
96
  if 'performance_history' not in st.session_state or not st.session_state['performance_history']:
97
  st.write("No performance data available.")
@@ -115,6 +117,7 @@ def analyze_performance():
115
  else:
116
  st.info("Performance is stable.")
117
 
 
118
  # Initialize session state
119
  if 'questions' not in st.session_state:
120
  st.session_state['questions'] = []
@@ -160,69 +163,93 @@ with st.form("question_form"):
160
  else:
161
  st.error("No questions were generated. Please try again.")
162
 
 
163
  # Display questions and collect responses
164
  if st.session_state['questions']:
165
  current_question = st.session_state['current_question']
166
-
167
- # Boundary check to avoid IndexError
168
- if current_question < len(st.session_state['questions']):
169
- st.write(f"Question {current_question + 1}: {st.session_state['questions'][current_question]}")
170
-
171
- with st.form(key=f"response_form_{current_question}"):
172
- st.session_state['response_input'] = st.text_area("Your Answer:", key="response_input")
173
- submitted = st.form_submit_button("Submit Answer")
174
-
175
- if submitted:
176
- response = st.session_state['response_input']
177
- if response:
178
- st.session_state['responses'].append(response)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
  st.session_state['current_question'] += 1
180
- st.session_state['response_input'] = "" # Clear the answer space
181
- st.session_state['interview_complete'] = st.session_state['current_question'] >= len(st.session_state['questions'])
182
-
183
- # Automatically generate feedback after all questions are answered
184
- if st.session_state['interview_complete']:
185
- with st.spinner("Generating feedback..."):
186
- st.session_state['feedback'] = generate_feedback(st.session_state['responses'])
187
- save_performance(role, topic, difficulty, st.session_state['feedback'])
188
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
  # Display feedback
190
- if st.session_state['feedback']:
191
- st.write("### Feedback")
192
  st.write(st.session_state['feedback'])
193
 
194
- # Display Tips and Resources Tabs
195
- tab1, tab2 = st.tabs(["Tips", "Resources"])
196
-
197
- with tab1:
198
- if st.session_state['tips']:
199
- st.write("### General Interview Tips")
200
- for tip in st.session_state['tips']:
201
- st.write(f"- {tip}")
202
-
203
- # Role-specific tips
204
- if st.button("Get Role-Specific Tips"):
205
- with st.spinner(f"Generating interview tips for a {role}..."):
206
- role_specific_tips = generate_tips(role=role, general=False)
207
- for tip in role_specific_tips:
208
- st.write(f"- {tip}")
209
-
210
- with tab2:
211
- st.write("### Resources")
212
- resources = get_resources(role)
213
- if resources:
214
- for resource in resources:
215
- st.write(f"- **{resource['type']}**: [{resource['title']}]({resource['link']})")
216
- else:
217
- st.write("No resources available for this role.")
218
-
219
- # Performance Analysis
 
220
  if st.button("Analyze Performance"):
221
- analyze_performance()
222
-
223
- # Schedule Mock Interview
224
- st.write("### Schedule a Mock Interview")
225
- mock_interview_date_time = st.date_input("Select Date and Time")
226
- if st.button("Schedule Mock Interview"):
227
- confirmation = schedule_mock_interview(mock_interview_date_time)
228
- st.success(confirmation)
 
29
  return []
30
 
31
  def generate_feedback(responses):
32
+ # prompt = "Provide feedback for the following interview responses along with that if the response is not upto mark give the word decline in it, otherwise give the word improve):\n" + "\n".join(responses)
33
  prompt = (
34
  "Evaluate the following interview responses. For each response, provide: \n"
35
  "1. Normal feedback.\n"
 
93
  def schedule_mock_interview(date_time):
94
  return f"Mock interview scheduled for {date_time}"
95
 
96
+
97
  def analyze_performance():
98
  if 'performance_history' not in st.session_state or not st.session_state['performance_history']:
99
  st.write("No performance data available.")
 
117
  else:
118
  st.info("Performance is stable.")
119
 
120
+
121
  # Initialize session state
122
  if 'questions' not in st.session_state:
123
  st.session_state['questions'] = []
 
163
  else:
164
  st.error("No questions were generated. Please try again.")
165
 
166
+
167
  # Display questions and collect responses
168
  if st.session_state['questions']:
169
  current_question = st.session_state['current_question']
170
+ st.write(f"Question {current_question + 1}: {st.session_state['questions'][current_question]}")
171
+
172
+ # Form for response
173
+ with st.form(key=f"response_form_{current_question}"):
174
+ user_response = st.text_area("Your Response:", key=f"user_response_{current_question}")
175
+ submit_response = st.form_submit_button("Submit")
176
+
177
+ if submit_response:
178
+ if user_response:
179
+ # Ensure no duplicate responses
180
+ if current_question < len(st.session_state['responses']):
181
+ st.session_state['responses'][current_question] = user_response
182
+ else:
183
+ st.session_state['responses'].append(user_response)
184
+
185
+ # Update the question index
186
+ if len(st.session_state['responses']) == len(st.session_state['questions']):
187
+ st.session_state['interview_complete'] = True
188
+ st.write("Interview Complete. Analyzing your responses...")
189
+ with st.spinner("Generating feedback..."):
190
+ feedback = generate_feedback(st.session_state['responses'])
191
+ st.session_state['feedback'] = feedback
192
+ save_performance(role, topic, difficulty, feedback)
193
+ st.session_state['questions'] = [] # Clear questions to prevent re-displaying
194
+ st.session_state['responses'] = [] # Clear responses
195
+ st.session_state['current_question'] = 0
196
+ else:
197
+ if current_question < len(st.session_state['questions']) - 1:
198
  st.session_state['current_question'] += 1
 
 
 
 
 
 
 
 
199
 
200
+ st.sidebar.header("Schedule Mock Interview")
201
+ mock_interview_date = st.sidebar.date_input("Select Date:")
202
+ mock_interview_time = st.sidebar.time_input("Select Time:")
203
+ if st.sidebar.button("Schedule Mock Interview"):
204
+ date_time = f"{mock_interview_date} {mock_interview_time}"
205
+ message = schedule_mock_interview(date_time)
206
+ st.sidebar.success(message)
207
+
208
+
209
+ # st.sidebar.header("Schedule Mock Interview")
210
+ # mock_interview_date = st.sidebar.date_input("Select Date:")
211
+ # mock_interview_time = st.sidebar.time_input("Select Time:")
212
+ # user_email = st.sidebar.text_input("Your Email:", key="user_email")
213
+ # if st.sidebar.button("Schedule Mock Interview"):
214
+ # if user_email:
215
+ # date_time = f"{mock_interview_date} {mock_interview_time}"
216
+ # message = schedule_mock_interview(date_time, user_email)
217
+ # st.sidebar.success(message)
218
+ # else:
219
+ # st.sidebar.error("Please enter your email address.")
220
+
221
+
222
  # Display feedback
223
+ if st.session_state['interview_complete']:
224
+ st.header("Feedback")
225
  st.write(st.session_state['feedback'])
226
 
227
+ # Display tips section
228
+ st.write("## Interview Tips")
229
+
230
+ if st.button("General Interview Tips"):
231
+ st.write("### General Tips")
232
+ for tip in st.session_state['tips']:
233
+ st.write(f"- {tip}")
234
+
235
+
236
+ role_for_tips = st.selectbox("Select Role for Tips:", ["Software Developer", "Data Analyst", "Marketing Manager"], key="role_tips_select")
237
+ if st.button("Role-Specific Interview Tips"):
238
+ st.write(f"### Tips for {role_for_tips}")
239
+ role_specific_tips = generate_tips(role=role_for_tips)
240
+ for tip in role_specific_tips:
241
+ st.write(f"- {tip}")
242
+
243
+ # Display resources section
244
+ st.write("## Interview Resources")
245
+ selected_role = st.selectbox("Select Role to Display Resources:", ["Software Developer", "Data Analyst", "Marketing Manager"], key="resources_select")
246
+ if st.button("Show Resources"):
247
+ resources = get_resources(selected_role)
248
+ st.write(f"### Resources for {selected_role}")
249
+ for resource in resources:
250
+ st.write(f"- **{resource['type']}:** [{resource['title']}]({resource['link']})")
251
+
252
+ # Performance analysis
253
+ st.write("## Analyze Performance")
254
  if st.button("Analyze Performance"):
255
+ analyze_performance()