Create interview_logic.py
Browse files- interview_logic.py +61 -0
interview_logic.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# PrepGenie_Gradio/interview_logic.py
|
| 2 |
+
|
| 3 |
+
# ... (existing imports) ...
|
| 4 |
+
import datetime # Add this import at the top
|
| 5 |
+
import interview_history # Import the new history module
|
| 6 |
+
|
| 7 |
+
# ... (existing functions: file_processing, getallinfo, etc.) ...
|
| 8 |
+
|
| 9 |
+
def finish_interview(all_questions_list, all_answers_list, all_feedback_list, resume_overview, selected_roles, user_id):
|
| 10 |
+
"""Gradio function to compile final results and save history."""
|
| 11 |
+
if not all_questions_list or not all_answers_list:
|
| 12 |
+
return "No interview data to display."
|
| 13 |
+
|
| 14 |
+
# --- Compile Results for Display ---
|
| 15 |
+
results = "**Interview Summary:**\n\n"
|
| 16 |
+
for i, q in enumerate(all_questions_list):
|
| 17 |
+
results += f"**Q{i+1}:** {q}\n"
|
| 18 |
+
if i < len(all_answers_list):
|
| 19 |
+
results += f"**Your Answer:** {all_answers_list[i]}\n"
|
| 20 |
+
if i < len(all_feedback_list):
|
| 21 |
+
results += f"**Feedback:** {all_feedback_list[i]}\n\n"
|
| 22 |
+
else:
|
| 23 |
+
results += "**Feedback:** Not available.\n\n"
|
| 24 |
+
|
| 25 |
+
# --- Prepare Data for Saving ---
|
| 26 |
+
# Only save if user is logged in (user_id is provided)
|
| 27 |
+
if user_id:
|
| 28 |
+
interview_summary_data = {
|
| 29 |
+
"timestamp": datetime.datetime.now().isoformat(), # Add timestamp
|
| 30 |
+
"resume_overview": resume_overview,
|
| 31 |
+
"selected_roles": selected_roles, # Make sure this is passed
|
| 32 |
+
"questions": all_questions_list,
|
| 33 |
+
"answers": all_answers_list,
|
| 34 |
+
"feedback": all_feedback_list,
|
| 35 |
+
"summary": results # Save the formatted summary as well
|
| 36 |
+
}
|
| 37 |
+
# --- Save to Firestore ---
|
| 38 |
+
success = interview_history.save_interview_history(user_id, interview_summary_data)
|
| 39 |
+
if success:
|
| 40 |
+
results += "\n---\n*Interview history saved successfully.*"
|
| 41 |
+
else:
|
| 42 |
+
results += "\n---\n*Failed to save interview history.*"
|
| 43 |
+
else:
|
| 44 |
+
results += "\n---\n*Not logged in. Interview history was not saved.*"
|
| 45 |
+
|
| 46 |
+
return results
|
| 47 |
+
|
| 48 |
+
# ... (rest of the file remains mostly the same, but update the call to finish_interview) ...
|
| 49 |
+
|
| 50 |
+
# In the part of interview_logic.py where `finish_interview` is called from the Gradio interface:
|
| 51 |
+
# Update the call to pass the additional arguments:
|
| 52 |
+
# OLD:
|
| 53 |
+
# finish_interview_btn.click(
|
| 54 |
+
# fn=finish_interview_wrapper,
|
| 55 |
+
# inputs=[user_state],
|
| 56 |
+
# outputs=[interview_results]
|
| 57 |
+
# )
|
| 58 |
+
# NEW (inside the wrapper function or by modifying the wrapper):
|
| 59 |
+
# You need to pass resume_overview, selected_roles, and user_id to the actual `finish_interview` function.
|
| 60 |
+
# This requires modifying the `finish_interview_wrapper` or the way it's called.
|
| 61 |
+
# Let's modify the wrapper function definition in app.py to pass these values.
|