import ollama import json import time from parser import parse_resume # --- Step 1: Parse Resume --- resume_file = r"C:\Users\prana\Downloads\ABDM\Documents\PranavKerkar_resume.pdf" parsed_data = parse_resume(resume_file) # --- Step 2: Context for AI --- context = f""" You are an AI Interviewer. Candidate's resume: {json.dumps(parsed_data, indent=2)} Rules: - Start with: "Am I audible?" - If 'no', retry politely. - Ask questions based on resume (skills, education, projects). - Wait 6–7 seconds before repeating if no response. - If unanswered after 2 tries, mark 'Unanswered' and move on. - End with: "Thank you for your time, results will be shared via email. Do you have any questions for me?" """ # --- Step 3: Helper Function for Rule-based Logic --- def rule_based_response(user_input, parsed_data): """Simple rule-based interview flow""" # Greeting / Audible check if user_input in ["no", "not really", "can't hear"]: return "AI Interviewer: Let me try again, can you hear me now?" if user_input in ["yes", "yeah", "yep"]: return f"AI Interviewer: Great, how are you {parsed_data.get('name','there')}?" # Resume skills skills = parsed_data.get("skills", []) for skill in skills: if skill.lower() in user_input: return f"AI Interviewer: Since you mentioned {skill}, can you rate yourself 1–10 and explain why?" # Education based if "b.tech" in user_input or "bachelor" in user_input: return "AI Interviewer: Can you share a project you did during your Bachelor's?" if "m.tech" in user_input or "master" in user_input: return "AI Interviewer: What was your Master's thesis about?" # Projects fallback if "project" in user_input: return "AI Interviewer: Can you walk me through your most challenging project?" return None # no rule → fallback to AI # --- Step 4: Interview Loop --- print("AI Interviewer: Am I audible?") unanswered_count = 0 last_question = None while True: candidate_input = input("Candidate: ").strip().lower() if candidate_input in ["exit", "quit", "bye"]: print("AI Interviewer: Thank you, goodbye.") break if candidate_input == "": if last_question and unanswered_count < 2: unanswered_count += 1 print("AI Interviewer: (waiting 6 seconds...)") time.sleep(6) print("AI Interviewer: Let me repeat —", last_question) continue elif last_question and unanswered_count >= 2: print("AI Interviewer: Marking this question as 'Unanswered'. Moving on.") unanswered_count = 0 last_question = None continue # 1. Rule-based first reply = rule_based_response(candidate_input, parsed_data) if reply: print(reply) last_question = reply.replace("AI Interviewer: ", "") unanswered_count = 0 continue # 2. Fallback to Ollama AI response = ollama.chat( model="llama2", messages=[ {"role": "system", "content": context}, {"role": "user", "content": candidate_input} ] ) interviewer_reply = response["message"]["content"] print("AI Interviewer:", interviewer_reply) last_question = interviewer_reply unanswered_count = 0