Spaces:
Running
Running
File size: 5,969 Bytes
f1e44b7 |
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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
import streamlit as st
from utils.cv_processor import evaluate_cv
from utils.interview_agent import InterviewAgent
from utils.report_generator import generate_report
import os
from datetime import datetime
def main():
st.set_page_config(page_title="AI Interview Agent", layout="wide")
st.title("AI Interview Agent")
st.write("Upload your CV and start your interview for the desired position.")
# Initialize session state
if 'interview_started' not in st.session_state:
st.session_state.interview_started = False
if 'current_question' not in st.session_state:
st.session_state.current_question = 0
if 'answers' not in st.session_state:
st.session_state.answers = []
if 'cv_evaluated' not in st.session_state:
st.session_state.cv_evaluated = False
if 'cv_rejected' not in st.session_state:
st.session_state.cv_rejected = False
# Step 1: Job Role and CV Upload
if not st.session_state.cv_evaluated:
with st.form("candidate_info"):
job_role = st.selectbox(
"Select the job role you're applying for:",
["Software Engineer", "Data Scientist", "Product Manager", "UX Designer", "DevOps Engineer"]
)
cv_file = st.file_uploader("Upload your CV (PDF or DOCX)", type=["pdf", "docx"])
submitted = st.form_submit_button("Submit")
if submitted and cv_file:
with st.spinner("Evaluating your CV..."):
# Save the uploaded file
file_path = f"data/temp_cv.{'pdf' if cv_file.type == 'application/pdf' else 'docx'}"
with open(file_path, "wb") as f:
f.write(cv_file.getbuffer())
# Evaluate CV
evaluation = evaluate_cv(file_path, job_role)
if evaluation["is_qualified"]:
st.session_state.cv_evaluated = True
st.session_state.job_role = job_role
st.session_state.cv_evaluation = evaluation
st.success("CV evaluation complete! You meet the basic requirements.")
else:
st.session_state.cv_rejected = True
st.session_state.rejection_reasons = evaluation["rejection_reasons"]
st.error("Your CV doesn't meet the requirements for this role.")
# Step 2: Interview Process
if st.session_state.cv_evaluated and not st.session_state.interview_started:
if st.button("Start Interview"):
st.session_state.interview_started = True
st.session_state.interview_agent = InterviewAgent(job_role, st.session_state.cv_evaluation["cv_summary"])
st.session_state.questions = st.session_state.interview_agent.get_questions()
st.experimental_rerun()
if st.session_state.interview_started:
interview_ui()
# Step 3: Show rejection if CV was rejected
if st.session_state.cv_rejected:
st.error("Unfortunately, your CV doesn't meet the requirements for this role.")
st.write("Reasons for rejection:")
for reason in st.session_state.rejection_reasons:
st.write(f"- {reason}")
if st.button("Try a different role"):
st.session_state.cv_rejected = False
st.session_state.cv_evaluated = False
st.experimental_rerun()
def interview_ui():
agent = st.session_state.interview_agent
questions = st.session_state.questions
# Show current question or completion
if st.session_state.current_question < len(questions):
question = questions[st.session_state.current_question]
st.subheader(f"Question {st.session_state.current_question + 1}/{len(questions)}")
st.write(question["text"])
# Answer input
answer = st.text_area("Your answer:", key=f"answer_{st.session_state.current_question}")
if st.button("Submit Answer"):
evaluation = agent.evaluate_answer(question, answer)
st.session_state.answers.append({
"question": question,
"answer": answer,
"evaluation": evaluation
})
st.session_state.current_question += 1
st.experimental_rerun()
else:
# Interview complete
st.success("Interview completed!")
final_evaluation = agent.final_evaluation(st.session_state.answers)
# Display results
st.subheader("Interview Results")
st.write(f"Overall Score: {final_evaluation['score']}/10")
st.write(f"Band: {final_evaluation['band']}")
st.subheader("Detailed Feedback")
for i, answer in enumerate(st.session_state.answers):
st.write(f"**Question {i+1}:** {answer['question']['text']}")
st.write(f"**Your Answer:** {answer['answer']}")
st.write(f"**Feedback:** {answer['evaluation']['feedback']}")
st.write("---")
# Generate and download report
report_path = generate_report(
st.session_state.job_role,
st.session_state.cv_evaluation["cv_summary"],
st.session_state.answers,
final_evaluation
)
with open(report_path, "rb") as f:
st.download_button(
"Download Interview Report",
f,
file_name=f"Interview_Report_{datetime.now().strftime('%Y%m%d_%H%M%S')}.pdf",
mime="application/pdf"
)
if st.button("Start New Interview"):
reset_session()
def reset_session():
for key in list(st.session_state.keys()):
del st.session_state[key]
st.experimental_rerun()
if __name__ == "__main__":
main() |