File size: 3,278 Bytes
640099a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from utils.cv_processor import CVProcessor
from utils.rag_agent import RAGInterviewAgent
from utils.evaluator import evaluate_answers
from utils.report_generator import generate_report
import os

def main():
    st.set_page_config(page_title="RAG Interview Agent", layout="wide")
    st.title("🧠 RAG-Powered Interview Agent")
    
    # Initialize session state
    if 'stage' not in st.session_state:
        st.session_state.stage = "upload"
    if 'answers' not in st.session_state:
        st.session_state.answers = []
    
    # CV Upload and Processing
    if st.session_state.stage == "upload":
        with st.form("candidate_info"):
            job_role = st.selectbox("Select job role:", 
                                  ["Software Engineer", "Data Scientist"])
            cv_file = st.file_uploader("Upload CV (PDF/DOCX)", 
                                     type=["pdf", "docx"])
            if st.form_submit_button("Submit"):
                if cv_file:
                    cv_path = f"data/temp_cv.{'pdf' if cv_file.type == 'application/pdf' else 'docx'}"
                    with open(cv_path, "wb") as f:
                        f.write(cv_file.getbuffer())
                    
                    processor = CVProcessor()
                    evaluation = processor.evaluate(cv_path, job_role)
                    
                    if evaluation["is_qualified"]:
                        st.session_state.cv_summary = evaluation["cv_summary"]
                        st.session_state.job_role = job_role
                        st.session_state.stage = "interview"
                        st.session_state.agent = RAGInterviewAgent(job_role, evaluation["cv_summary"])
                        st.rerun()
                    else:
                        st.error("CV doesn't meet requirements")

    # Interview Process
    elif st.session_state.stage == "interview":
        agent = st.session_state.agent
        question = agent.get_current_question()
        
        st.subheader(f"Question {agent.current_q + 1}/{len(agent.questions)}")
        st.write(question["text"])
        
        answer = st.text_area("Your answer:")
        
        if st.button("Submit Answer"):
            evaluation = agent.evaluate_answer(answer)
            st.session_state.answers.append({
                "question": question,
                "answer": answer,
                "evaluation": evaluation
            })
            
            if agent.current_q < len(agent.questions) - 1:
                agent.next_question()
            else:
                st.session_state.stage = "results"
                st.rerun()
    
    # Results Display
    elif st.session_state.stage == "results":
        final_eval = evaluate_answers(st.session_state.answers)
        st.success("Interview Complete!")
        st.subheader(f"Overall Score: {final_eval['score']}/10")
        
        report_path = generate_report(
            st.session_state.job_role,
            st.session_state.cv_summary,
            st.session_state.answers,
            final_eval
        )
        
        with open(report_path, "rb") as f:
            st.download_button("Download Report", f, "interview_report.pdf")

if __name__ == "__main__":
    main()