Spaces:
Runtime error
Runtime error
File size: 3,341 Bytes
1207440 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | 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
|