Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from utils.cv_processor import CVProcessor
|
3 |
+
from utils.rag_agent import RAGInterviewAgent
|
4 |
+
from utils.evaluator import evaluate_answers
|
5 |
+
from utils.report_generator import generate_report
|
6 |
+
import os
|
7 |
+
|
8 |
+
def main():
|
9 |
+
st.set_page_config(page_title="RAG Interview Agent", layout="wide")
|
10 |
+
st.title("🧠 RAG-Powered Interview Agent")
|
11 |
+
|
12 |
+
# Initialize session state
|
13 |
+
if 'stage' not in st.session_state:
|
14 |
+
st.session_state.stage = "upload"
|
15 |
+
if 'answers' not in st.session_state:
|
16 |
+
st.session_state.answers = []
|
17 |
+
|
18 |
+
# CV Upload and Processing
|
19 |
+
if st.session_state.stage == "upload":
|
20 |
+
with st.form("candidate_info"):
|
21 |
+
job_role = st.selectbox("Select job role:",
|
22 |
+
["Software Engineer", "Data Scientist"])
|
23 |
+
cv_file = st.file_uploader("Upload CV (PDF/DOCX)",
|
24 |
+
type=["pdf", "docx"])
|
25 |
+
if st.form_submit_button("Submit"):
|
26 |
+
if cv_file:
|
27 |
+
cv_path = f"data/temp_cv.{'pdf' if cv_file.type == 'application/pdf' else 'docx'}"
|
28 |
+
with open(cv_path, "wb") as f:
|
29 |
+
f.write(cv_file.getbuffer())
|
30 |
+
|
31 |
+
processor = CVProcessor()
|
32 |
+
evaluation = processor.evaluate(cv_path, job_role)
|
33 |
+
|
34 |
+
if evaluation["is_qualified"]:
|
35 |
+
st.session_state.cv_summary = evaluation["cv_summary"]
|
36 |
+
st.session_state.job_role = job_role
|
37 |
+
st.session_state.stage = "interview"
|
38 |
+
st.session_state.agent = RAGInterviewAgent(job_role, evaluation["cv_summary"])
|
39 |
+
st.rerun()
|
40 |
+
else:
|
41 |
+
st.error("CV doesn't meet requirements")
|
42 |
+
|
43 |
+
# Interview Process
|
44 |
+
elif st.session_state.stage == "interview":
|
45 |
+
agent = st.session_state.agent
|
46 |
+
question = agent.get_current_question()
|
47 |
+
|
48 |
+
st.subheader(f"Question {agent.current_q + 1}/{len(agent.questions)}")
|
49 |
+
st.write(question["text"])
|
50 |
+
|
51 |
+
answer = st.text_area("Your answer:")
|
52 |
+
|
53 |
+
if st.button("Submit Answer"):
|
54 |
+
evaluation = agent.evaluate_answer(answer)
|
55 |
+
st.session_state.answers.append({
|
56 |
+
"question": question,
|
57 |
+
"answer": answer,
|
58 |
+
"evaluation": evaluation
|
59 |
+
})
|
60 |
+
|
61 |
+
if agent.current_q < len(agent.questions) - 1:
|
62 |
+
agent.next_question()
|
63 |
+
else:
|
64 |
+
st.session_state.stage = "results"
|
65 |
+
st.rerun()
|
66 |
+
|
67 |
+
# Results Display
|
68 |
+
elif st.session_state.stage == "results":
|
69 |
+
final_eval = evaluate_answers(st.session_state.answers)
|
70 |
+
st.success("Interview Complete!")
|
71 |
+
st.subheader(f"Overall Score: {final_eval['score']}/10")
|
72 |
+
|
73 |
+
report_path = generate_report(
|
74 |
+
st.session_state.job_role,
|
75 |
+
st.session_state.cv_summary,
|
76 |
+
st.session_state.answers,
|
77 |
+
final_eval
|
78 |
+
)
|
79 |
+
|
80 |
+
with open(report_path, "rb") as f:
|
81 |
+
st.download_button("Download Report", f, "interview_report.pdf")
|
82 |
+
|
83 |
+
if __name__ == "__main__":
|
84 |
+
main()
|