rishabhpr commited on
Commit
32cb41d
·
verified ·
1 Parent(s): d903541

add code interpreter

Browse files
Files changed (1) hide show
  1. app.py +19 -2
app.py CHANGED
@@ -157,8 +157,25 @@ Enter a company name, topic, and level of difficulty, and it will transform a re
157
  Continue chatting with the assistant in the chatbox below.
158
  """)
159
 
160
- # Right sidebar toggleable debug logs
161
  with st.expander("Debug Logs (Toggle On/Off)", expanded=False):
162
  if len(st.session_state.debug_logs) > 0:
163
  for log_entry in reversed(st.session_state.debug_logs): # Show most recent logs first
164
- st.write(log_entry)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  Continue chatting with the assistant in the chatbox below.
158
  """)
159
 
160
+ # Right sidebar toggleable debug logs and code interpreter section
161
  with st.expander("Debug Logs (Toggle On/Off)", expanded=False):
162
  if len(st.session_state.debug_logs) > 0:
163
  for log_entry in reversed(st.session_state.debug_logs): # Show most recent logs first
164
+ st.write(log_entry)
165
+
166
+ st.sidebar.markdown("---")
167
+ st.sidebar.markdown("## Python Code Interpreter")
168
+ code_input = st.sidebar.text_area("Write your Python code here:")
169
+ if st.sidebar.button("Run Code"):
170
+ try:
171
+ exec_globals = {}
172
+ exec(code_input, exec_globals) # Execute user-provided code safely within its own scope.
173
+ output_key = [k for k in exec_globals.keys() if k != "__builtins__"]
174
+ if output_key:
175
+ output_value = exec_globals[output_key[0]]
176
+ st.sidebar.success(f"Output: {output_value}")
177
+ else:
178
+ st.sidebar.success("Code executed successfully!")
179
+
180
+ except Exception as e:
181
+ st.sidebar.error(f"Error: {e}")