Sa-m commited on
Commit
ad34aa4
·
verified ·
1 Parent(s): b7e9358

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +86 -62
app.py CHANGED
@@ -48,13 +48,13 @@ def apply_ui_updates(updates_dict):
48
 
49
  # --- Navigation Functions ---
50
  def navigate_to_interview():
51
- return (gr.update(visible=True), gr.update(visible=False))
52
 
53
  def navigate_to_chat():
54
- return (gr.update(visible=False), gr.update(visible=True))
55
 
56
  def navigate_to_history():
57
- return (gr.update(visible=False), gr.update(visible=False))
58
 
59
  # --- Event Handler Functions (Orchestrators) ---
60
  def process_resume_handler(file_obj):
@@ -149,16 +149,6 @@ def submit_interview_handler(interview_state):
149
  result = interview_logic.submit_interview_logic(interview_state, TEXT_MODEL)
150
  ui_updates = apply_ui_updates(result["ui_updates"])
151
 
152
- # --- NEW: Save Interview History ---
153
- # Since we have no user_id, we'll save it in a local state object.
154
- # We will use the `interview_state` itself to hold the history.
155
- # But first, let's create a separate state for history.
156
- # We'll modify this later when we integrate the full history logic.
157
- # For now, we just want to see the report and chart.
158
- # The actual history saving will be handled by the interview_logic module.
159
- # It will store the data in a list within the `interview_state` under a key like 'history'.
160
- # This is a temporary solution until we have a proper backend.
161
-
162
  # Handle special updates for report and chart that need value setting
163
  report_update = ui_updates.get("evaluation_report_display", gr.update())
164
  if "gr_show_and_update" in result["ui_updates"].values():
@@ -208,54 +198,89 @@ with gr.Blocks(title="PrepGenie - Mock Interviewer") as demo:
208
  )
209
 
210
  # --- Main App Sections ---
211
- with gr.Column(visible=False) as main_app:
212
- with gr.Row():
213
- with gr.Column(scale=1):
214
- logout_btn = gr.Button("Logout")
215
- with gr.Column(scale=4): # This line is correct
216
- welcome_display = gr.Markdown("### Welcome, User!") # This line must be indented
217
-
218
- with gr.Row():
219
- with gr.Column(scale=1):
220
- interview_btn = gr.Button("Mock Interview")
221
- if CHAT_MODULE_AVAILABLE:
222
- chat_btn = gr.Button("Chat with Resume")
223
- else:
224
- chat_btn = gr.Button("Chat with Resume (Unavailable)", interactive=False)
225
- history_btn = gr.Button("My Interview History")
226
-
227
- with gr.Column(scale=4): # This line is correct
228
- # --- Interview Section ---
229
- with gr.Column(visible=False) as interview_selection:
230
- gr.Markdown("## Mock Interview")
231
- # ... (rest of the interview_selection content) ...
232
-
233
- # --- Chat Section ---
234
- if CHAT_MODULE_AVAILABLE:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
  with gr.Column(visible=False) as chat_selection:
236
- gr.Markdown("## Chat with Resume")
237
- # ... (rest of the chat_selection content) ...
238
- else:
239
- with gr.Column(visible=False) as chat_selection:
240
- gr.Markdown("## Chat with Resume (Unavailable)")
241
- gr.Textbox(value="Chat module is not available.", interactive=False)
242
-
243
- # --- History Section ---
244
- with gr.Column(visible=False) as history_selection:
245
- gr.Markdown("## Your Interview History")
246
- load_history_btn = gr.Button("Load My Past Interviews")
247
- history_output = gr.Textbox(label="Past Interviews", max_lines=30, interactive=False, visible=True)
248
-
249
- # Assign view variables for navigation
250
- interview_view = interview_selection
251
- chat_view = chat_selection
252
- history_view = history_selection
253
-
254
- # Navigation button listeners
255
- interview_btn.click(fn=navigate_to_interview, inputs=None, outputs=[interview_view, chat_view, history_view])
256
- if CHAT_MODULE_AVAILABLE:
257
- chat_btn.click(fn=navigate_to_chat, inputs=None, outputs=[interview_view, chat_view, history_view])
258
- history_btn.click(fn=navigate_to_history, inputs=None, outputs=[interview_view, chat_view, history_view])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
 
260
  # --- Event Listeners for Interview ---
261
  process_btn_interview.click(
@@ -330,8 +355,7 @@ with gr.Column(visible=False) as main_app:
330
  outputs=[query_input, chatbot]
331
  )
332
 
333
- # --- NEW: Event Listener for History ---
334
- # This function will use the interview_history_state to display past interviews
335
  def load_user_history_local(interview_history_state):
336
  """Function to load and format interview history for display in the UI."""
337
  if not interview_history_state:
 
48
 
49
  # --- Navigation Functions ---
50
  def navigate_to_interview():
51
+ return (gr.update(visible=True), gr.update(visible=False), gr.update(visible=False))
52
 
53
  def navigate_to_chat():
54
+ return (gr.update(visible=False), gr.update(visible=True), gr.update(visible=False))
55
 
56
  def navigate_to_history():
57
+ return (gr.update(visible=False), gr.update(visible=False), gr.update(visible=True))
58
 
59
  # --- Event Handler Functions (Orchestrators) ---
60
  def process_resume_handler(file_obj):
 
149
  result = interview_logic.submit_interview_logic(interview_state, TEXT_MODEL)
150
  ui_updates = apply_ui_updates(result["ui_updates"])
151
 
 
 
 
 
 
 
 
 
 
 
152
  # Handle special updates for report and chart that need value setting
153
  report_update = ui_updates.get("evaluation_report_display", gr.update())
154
  if "gr_show_and_update" in result["ui_updates"].values():
 
198
  )
199
 
200
  # --- Main App Sections ---
201
+ with gr.Column(visible=True) as main_app:
202
+ with gr.Row():
203
+ with gr.Column(scale=1):
204
+ # Navigation buttons
205
+ mock_interview_btn = gr.Button("Mock Interview")
206
+ if CHAT_MODULE_AVAILABLE:
207
+ chat_btn = gr.Button("Chat with Resume")
208
+ else:
209
+ chat_btn = gr.Button("Chat with Resume (Unavailable)", interactive=False)
210
+ history_btn = gr.Button("My Interview History")
211
+
212
+ # Main content area - this needs to be a single column that contains all the sections
213
+ with gr.Column(scale=4):
214
+ # --- Interview Section ---
215
+ with gr.Column(visible=True) as interview_selection:
216
+ gr.Markdown("## Mock Interview")
217
+ with gr.Row():
218
+ with gr.Column():
219
+ file_upload_interview = gr.File(label="Upload Resume (PDF)", file_types=[".pdf"])
220
+ process_btn_interview = gr.Button("Process Resume")
221
+ with gr.Column():
222
+ file_status_interview = gr.Textbox(label="Status", interactive=False)
223
+ role_selection = gr.Dropdown(
224
+ choices=["Data Scientist", "Software Engineer", "Product Manager", "Data Analyst", "Business Analyst"],
225
+ multiselect=True, label="Select Job Role(s)", visible=False
226
+ )
227
+ start_interview_btn = gr.Button("Start Interview", visible=False)
228
+ question_display = gr.Textbox(label="Question", interactive=False, visible=False)
229
+ answer_instructions = gr.Markdown("Click 'Record Answer' and speak your response.", visible=False)
230
+ audio_input = gr.Audio(label="Record Answer", type="numpy", visible=False)
231
+ submit_answer_btn = gr.Button("Submit Answer", visible=False)
232
+ next_question_btn = gr.Button("Next Question", visible=False)
233
+ submit_interview_btn = gr.Button("Submit Interview", visible=False, variant="primary")
234
+ answer_display = gr.Textbox(label="Your Answer", interactive=False, visible=False)
235
+ feedback_display = gr.Textbox(label="Feedback", interactive=False, visible=False)
236
+ metrics_display = gr.JSON(label="Metrics", visible=False)
237
+ processed_resume_data_hidden_interview = gr.Textbox(visible=False)
238
+ # --- Evaluation Results Section ---
239
+ with gr.Column(visible=False) as evaluation_selection:
240
+ gr.Markdown("## Interview Evaluation Results")
241
+ evaluation_report_display = gr.Markdown(label="Your Evaluation Report", visible=False)
242
+ evaluation_chart_display = gr.Image(label="Skills Breakdown", type="pil", visible=False)
243
+
244
+ # --- Chat Section ---
245
  with gr.Column(visible=False) as chat_selection:
246
+ if CHAT_MODULE_AVAILABLE:
247
+ gr.Markdown("## Chat with Resume")
248
+ with gr.Row():
249
+ with gr.Column():
250
+ file_upload_chat = gr.File(label="Upload Resume (PDF)", file_types=[".pdf"])
251
+ process_chat_btn = gr.Button("Process Resume")
252
+ with gr.Column():
253
+ file_status_chat = gr.Textbox(label="Status", interactive=False)
254
+ chatbot = gr.Chatbot(label="Chat History", visible=False, type="messages")
255
+ query_input = gr.Textbox(label="Ask about your resume", placeholder="Type your question here...", visible=False)
256
+ send_btn = gr.Button("Send", visible=False)
257
+ else:
258
+ gr.Markdown("## Chat with Resume (Unavailable)")
259
+ gr.Textbox(value="Chat module is not available.", interactive=False)
260
+
261
+ # --- History Section ---
262
+ with gr.Column(visible=False) as history_selection:
263
+ gr.Markdown("## Your Interview History")
264
+ load_history_btn = gr.Button("Load My Past Interviews")
265
+ history_output = gr.Textbox(label="Past Interviews", max_lines=30, interactive=False, visible=True)
266
+
267
+ # --- Event Listeners for Navigation ---
268
+ mock_interview_btn.click(
269
+ fn=navigate_to_interview,
270
+ inputs=None,
271
+ outputs=[interview_selection, chat_selection, history_selection]
272
+ )
273
+ if CHAT_MODULE_AVAILABLE:
274
+ chat_btn.click(
275
+ fn=navigate_to_chat,
276
+ inputs=None,
277
+ outputs=[interview_selection, chat_selection, history_selection]
278
+ )
279
+ history_btn.click(
280
+ fn=navigate_to_history,
281
+ inputs=None,
282
+ outputs=[interview_selection, chat_selection, history_selection]
283
+ )
284
 
285
  # --- Event Listeners for Interview ---
286
  process_btn_interview.click(
 
355
  outputs=[query_input, chatbot]
356
  )
357
 
358
+ # --- Event Listener for History ---
 
359
  def load_user_history_local(interview_history_state):
360
  """Function to load and format interview history for display in the UI."""
361
  if not interview_history_state: