Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -28,10 +28,9 @@ model = SentenceTransformer("all-MiniLM-L6-v2").to(device)
|
|
28 |
with open("technical_interviewer_prompt.txt", "r") as file:
|
29 |
technical_interviewer_prompt = file.read()
|
30 |
|
31 |
-
# Load prompts from files
|
32 |
with open("question_generation_prompt.txt", "r") as file:
|
33 |
question_generation_prompt = file.read()
|
34 |
-
|
35 |
st.title("Real-World Programming Question Mock Interview")
|
36 |
|
37 |
# Initialize session state variables
|
@@ -107,41 +106,38 @@ if generate_button:
|
|
107 |
f"\nPlease create a real-world interview question based on this information."
|
108 |
)
|
109 |
|
110 |
-
# Generate response using GPT with detailed prompt
|
111 |
-
response = generate_response([{"role": "user", "content": detailed_prompt}])
|
112 |
|
113 |
-
# Store generated question in session state for persistence
|
114 |
st.session_state.generated_question = response
|
115 |
|
116 |
-
# Add the generated question
|
|
|
117 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
118 |
|
119 |
# Enable follow-up mode after generating the initial question
|
120 |
st.session_state.follow_up_mode = True
|
121 |
|
122 |
# Display chat messages from history on app rerun (for subsequent conversation)
|
123 |
-
for message in st.session_state.messages:
|
124 |
-
|
125 |
-
|
126 |
-
st.markdown(message["content"])
|
127 |
|
128 |
# Chatbox for subsequent conversations with assistant (follow-up mode)
|
129 |
if st.session_state.follow_up_mode:
|
130 |
if user_input := st.chat_input("Continue your conversation or ask follow-up questions here:"):
|
131 |
-
#
|
132 |
-
with st.chat_message("user"):
|
133 |
-
st.markdown(user_input)
|
134 |
-
|
135 |
st.session_state.messages.append({"role": "user", "content": user_input})
|
136 |
|
137 |
-
# Generate assistant's response based on follow-up input
|
138 |
-
assistant_response = generate_response(
|
139 |
-
[{"role": "user", "content": user_input}]
|
140 |
-
)
|
141 |
|
|
|
142 |
with st.chat_message("assistant"):
|
143 |
st.markdown(assistant_response)
|
144 |
|
|
|
145 |
st.session_state.messages.append({"role": "assistant", "content": assistant_response})
|
146 |
|
147 |
st.sidebar.markdown("""
|
@@ -151,32 +147,15 @@ Enter a company name, topic, and level of difficulty, and it will transform a re
|
|
151 |
Continue chatting with the AI interviewer in the chatbox.
|
152 |
""")
|
153 |
|
154 |
-
# Sidebar content to display persistent generated question
|
155 |
st.sidebar.markdown("## Generated Question")
|
156 |
if st.session_state.generated_question:
|
157 |
st.sidebar.markdown(st.session_state.generated_question)
|
158 |
else:
|
159 |
st.sidebar.markdown("_No question generated yet._")
|
160 |
|
161 |
-
# Right sidebar toggleable debug logs
|
162 |
with st.expander("Debug Logs (Toggle On/Off)", expanded=False):
|
163 |
if len(st.session_state.debug_logs) > 0:
|
164 |
for log_entry in reversed(st.session_state.debug_logs): # Show most recent logs first
|
165 |
st.write(log_entry)
|
166 |
-
|
167 |
-
st.sidebar.markdown("---")
|
168 |
-
st.sidebar.markdown("## Python Code Interpreter")
|
169 |
-
code_input = st.sidebar.text_area("Write your Python code here:")
|
170 |
-
if st.sidebar.button("Run Code"):
|
171 |
-
try:
|
172 |
-
exec_globals = {}
|
173 |
-
exec(code_input, exec_globals) # Execute user-provided code safely within its own scope.
|
174 |
-
output_key = [k for k in exec_globals.keys() if k != "__builtins__"]
|
175 |
-
if output_key:
|
176 |
-
output_value = exec_globals[output_key[0]]
|
177 |
-
st.sidebar.success(f"Output: {output_value}")
|
178 |
-
else:
|
179 |
-
st.sidebar.success("Code executed successfully!")
|
180 |
-
|
181 |
-
except Exception as e:
|
182 |
-
st.sidebar.error(f"Error: {e}")
|
|
|
28 |
with open("technical_interviewer_prompt.txt", "r") as file:
|
29 |
technical_interviewer_prompt = file.read()
|
30 |
|
|
|
31 |
with open("question_generation_prompt.txt", "r") as file:
|
32 |
question_generation_prompt = file.read()
|
33 |
+
|
34 |
st.title("Real-World Programming Question Mock Interview")
|
35 |
|
36 |
# Initialize session state variables
|
|
|
106 |
f"\nPlease create a real-world interview question based on this information."
|
107 |
)
|
108 |
|
109 |
+
# Generate response using GPT-4 with detailed prompt and debugging logs
|
110 |
+
response = generate_response([{"role": "user", "content": detailed_prompt}]) # Question generation prompt excluded here
|
111 |
|
112 |
+
# Store generated question in session state for persistence
|
113 |
st.session_state.generated_question = response
|
114 |
|
115 |
+
# Add the generated question and technical interviewer prompt as hidden start for follow-up
|
116 |
+
st.session_state.messages.append({"role": "user", "content": technical_interviewer_prompt})
|
117 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
118 |
|
119 |
# Enable follow-up mode after generating the initial question
|
120 |
st.session_state.follow_up_mode = True
|
121 |
|
122 |
# Display chat messages from history on app rerun (for subsequent conversation)
|
123 |
+
for message in st.session_state.messages[2:]: # Exclude the hidden messages (first two)
|
124 |
+
with st.chat_message(message["role"]):
|
125 |
+
st.markdown(message["content"])
|
|
|
126 |
|
127 |
# Chatbox for subsequent conversations with assistant (follow-up mode)
|
128 |
if st.session_state.follow_up_mode:
|
129 |
if user_input := st.chat_input("Continue your conversation or ask follow-up questions here:"):
|
130 |
+
# Add the user's input to the session state
|
|
|
|
|
|
|
131 |
st.session_state.messages.append({"role": "user", "content": user_input})
|
132 |
|
133 |
+
# Generate assistant's response based on follow-up input
|
134 |
+
assistant_response = generate_response(st.session_state.messages)
|
|
|
|
|
135 |
|
136 |
+
# Display the assistant's response
|
137 |
with st.chat_message("assistant"):
|
138 |
st.markdown(assistant_response)
|
139 |
|
140 |
+
# Append the assistant's response to the conversation history
|
141 |
st.session_state.messages.append({"role": "assistant", "content": assistant_response})
|
142 |
|
143 |
st.sidebar.markdown("""
|
|
|
147 |
Continue chatting with the AI interviewer in the chatbox.
|
148 |
""")
|
149 |
|
150 |
+
# Sidebar content to display persistent generated question
|
151 |
st.sidebar.markdown("## Generated Question")
|
152 |
if st.session_state.generated_question:
|
153 |
st.sidebar.markdown(st.session_state.generated_question)
|
154 |
else:
|
155 |
st.sidebar.markdown("_No question generated yet._")
|
156 |
|
157 |
+
# Right sidebar toggleable debug logs
|
158 |
with st.expander("Debug Logs (Toggle On/Off)", expanded=False):
|
159 |
if len(st.session_state.debug_logs) > 0:
|
160 |
for log_entry in reversed(st.session_state.debug_logs): # Show most recent logs first
|
161 |
st.write(log_entry)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|