AKKI-AFK commited on
Commit
1b062bc
·
verified ·
1 Parent(s): ce6b914

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -0
app.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from interview_logic import InterviewAgent
3
+ from pathlib import Path
4
+ import os
5
+ import json
6
+ from dotenv import load_dotenv
7
+
8
+ load_dotenv()
9
+
10
+ UPLOAD_DIR = Path(os.getenv('UPLOAD_DIR', './uploads'))
11
+ SESSION_DIR = Path(os.getenv('SESSION_DIR', './sessions'))
12
+ UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
13
+ SESSION_DIR.mkdir(parents=True, exist_ok=True)
14
+
15
+ st.set_page_config(page_title='Excel Mock Interviewer - PoC', layout='centered')
16
+
17
+ if 'agent' not in st.session_state:
18
+ st.session_state.agent = InterviewAgent()
19
+
20
+ agent = st.session_state.agent
21
+
22
+ st.title('AI-Powered Excel Mock Interviewer — PoC')
23
+ st.write('Quick demo: answer questions or upload an Excel workbook when asked.')
24
+
25
+ for entry in agent.history:
26
+ role = entry['role']
27
+ text = entry['text']
28
+ if role == 'agent':
29
+ st.markdown(f"**Interviewer:** {text}")
30
+ else:
31
+ st.markdown(f"**You:** {text}")
32
+
33
+ def save_session():
34
+ path = SESSION_DIR / f"{agent.session_id}.json"
35
+ with open(path, "w", encoding="utf-8") as f:
36
+ json.dump(agent.summary(), f, indent=2)
37
+
38
+ if agent.active:
39
+ q = agent.current_question
40
+ st.markdown(f"### Question: {q['text']}")
41
+ txt = st.text_area('Your answer (text or formula)', key='answer_text')
42
+ file = st.file_uploader('Upload workbook (.xlsx) if requested', type=['xlsx'])
43
+
44
+ col1, col2 = st.columns(2)
45
+ with col1:
46
+ if st.button('Submit Answer'):
47
+ if not txt.strip():
48
+ st.warning('Type an answer or upload a file before submitting.')
49
+ else:
50
+ agent.record_answer(txt)
51
+ save_session()
52
+ st.rerun()
53
+ with col2:
54
+ if st.button('Submit Workbook'):
55
+ if not file:
56
+ st.warning('Choose an .xlsx file to upload')
57
+ else:
58
+ dst = UPLOAD_DIR / f"{agent.session_id}--{file.name}"
59
+ with open(dst, 'wb') as f:
60
+ f.write(file.getbuffer())
61
+ agent.record_upload(str(dst))
62
+ save_session()
63
+ st.rerun()
64
+ else:
65
+ st.success('Interview complete — see summary below')
66
+ st.markdown('## Summary')
67
+ st.write(agent.summary())
68
+ if st.button('Download transcript (JSON)'):
69
+ st.download_button(
70
+ 'Download JSON',
71
+ data=agent.transcript_json(),
72
+ file_name=f'{agent.session_id}-transcript.json'
73
+ )
74
+
75
+ with st.expander('Admin: internal state'):
76
+ st.write({
77
+ 'session_id': agent.session_id,
78
+ 'current_q_idx': agent.idx,
79
+ 'history_len': len(agent.history)
80
+ })