Spaces:
Running
Running
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() |