Spaces:
Runtime error
Runtime error
Download code_executor.py from nsgupta1/MockInterviewBot: direct link, hf CLI and curl.
- Browser
- Download file 909 Bytes
-
https://huggingface.co/spaces/nsgupta1/MockInterviewBot/resolve/main/code_executor.py
- Command line
-
hf download hf://spaces/nsgupta1/MockInterviewBot/code_executor.py
-
curl -L -o code_executor.py https://huggingface.co/spaces/nsgupta1/MockInterviewBot/resolve/main/code_executor.py
909 Bytes
| import streamlit as st | |
| def execute_code(code_input): | |
| try: | |
| exec_globals = {} | |
| exec(f"def user_solution():\n{code_input}", exec_globals) | |
| user_solution = exec_globals.get('user_solution', None) | |
| if st.session_state.sample_test_case: | |
| test_args = eval(st.session_state.sample_test_case) | |
| if not isinstance(test_args, tuple): | |
| test_args = (test_args,) | |
| returned_output = user_solution(*test_args) | |
| else: | |
| returned_output = user_solution() | |
| st.sidebar.markdown(f"**Your Output:** {returned_output}") | |
| if str(returned_output) == st.session_state.expected_output: | |
| st.sidebar.success("Your output matches the expected output!") | |
| else: | |
| st.sidebar.error("Your output does not match the expected output.") | |
| except Exception as e: | |
| st.sidebar.error(f"Error: {e}") | |