Mohinikathro commited on
Commit
a533e1d
Β·
verified Β·
1 Parent(s): d758394

changes saved to app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py CHANGED
@@ -5,6 +5,7 @@ import torch
5
  import os
6
  import gradio_client.utils as client_utils
7
  import sys
 
8
 
9
  # ===============================
10
  # Recursion Handling Fix
@@ -232,9 +233,33 @@ def end_interview(state):
232
  with open(filename, "w") as f:
233
  json.dump(summary, f, indent=4)
234
 
 
 
 
 
 
 
 
 
 
 
235
  state["conversation"].append({"role": "System", "content": f"βœ… Interview ended. \nFinal Score: {summary['score']} ({summary['category']})"})
236
  return convert_for_gradio(state["conversation"]), state
237
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
  def clear_state():
239
  return [], reset_state("", "", "", "Entry-Level")
240
 
@@ -263,11 +288,18 @@ with gr.Blocks() as demo:
263
  exit_button = gr.Button("Exit Interview")
264
  clear_button = gr.Button("Clear Session")
265
 
 
 
 
 
 
266
  state = gr.State(value=reset_state("", "", "", "Entry-Level"))
267
 
 
268
  start_button.click(start_interview, inputs=[name_input, domain_input, company_input, level_input], outputs=[chatbot, state])
269
  submit_button.click(submit_response, inputs=[response_input, state], outputs=[chatbot, state]).then(lambda: "", None, response_input)
270
  exit_button.click(end_interview, inputs=state, outputs=[chatbot, state])
271
  clear_button.click(clear_state, outputs=[chatbot, state])
 
272
 
273
  demo.launch()
 
5
  import os
6
  import gradio_client.utils as client_utils
7
  import sys
8
+ import tempfile
9
 
10
  # ===============================
11
  # Recursion Handling Fix
 
233
  with open(filename, "w") as f:
234
  json.dump(summary, f, indent=4)
235
 
236
+ # Add detailed evaluations to the conversation
237
+ for ev in state["evaluations"]:
238
+ detail = (
239
+ f"πŸ“Œ **Question:** {ev['question']}\n"
240
+ f"πŸ’¬ **Your Response:** {ev['response']}\n"
241
+ f"🟒 **Rating:** {ev['rating']}\n"
242
+ f"πŸ’‘ **Suggestion:** {ev['suggestion']}"
243
+ )
244
+ state["conversation"].append({"role": "System", "content": detail})
245
+
246
  state["conversation"].append({"role": "System", "content": f"βœ… Interview ended. \nFinal Score: {summary['score']} ({summary['category']})"})
247
  return convert_for_gradio(state["conversation"]), state
248
 
249
+ def prepare_downloadable_summary(state):
250
+ summary = {
251
+ "name": state["name"],
252
+ "domain": state["domain"],
253
+ "level": state["level"],
254
+ "company": state["company"],
255
+ "score": f"{sum(rating_scores.get(ev['rating'], 0) for ev in state['evaluations'])}/{len(state['evaluations']) * 3}",
256
+ "evaluations": state["evaluations"]
257
+ }
258
+
259
+ with tempfile.NamedTemporaryFile(mode="w+", delete=False, suffix=".json") as f:
260
+ json.dump(summary, f, indent=4)
261
+ return f.name # Return the path to the downloadable file
262
+
263
  def clear_state():
264
  return [], reset_state("", "", "", "Entry-Level")
265
 
 
288
  exit_button = gr.Button("Exit Interview")
289
  clear_button = gr.Button("Clear Session")
290
 
291
+ with gr.Row():
292
+ download_button = gr.Button("πŸ“₯ Download Evaluation Report")
293
+ download_file = gr.File(label="Download", visible=True)
294
+
295
+ # Session state holder
296
  state = gr.State(value=reset_state("", "", "", "Entry-Level"))
297
 
298
+ # Hooking up logic to UI
299
  start_button.click(start_interview, inputs=[name_input, domain_input, company_input, level_input], outputs=[chatbot, state])
300
  submit_button.click(submit_response, inputs=[response_input, state], outputs=[chatbot, state]).then(lambda: "", None, response_input)
301
  exit_button.click(end_interview, inputs=state, outputs=[chatbot, state])
302
  clear_button.click(clear_state, outputs=[chatbot, state])
303
+ download_button.click(prepare_downloadable_summary, inputs=[state], outputs=[download_file])
304
 
305
  demo.launch()