Spaces:
Running
Running
Update pages/2_CodeSimulator.py
Browse files- pages/2_CodeSimulator.py +5 -3
pages/2_CodeSimulator.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import torch
|
| 3 |
import io
|
| 4 |
import sys
|
| 5 |
|
|
@@ -9,7 +8,7 @@ def execute_code(code):
|
|
| 9 |
old_stdout = sys.stdout
|
| 10 |
sys.stdout = mystdout = io.StringIO()
|
| 11 |
|
| 12 |
-
global_vars = {}
|
| 13 |
local_vars = {}
|
| 14 |
try:
|
| 15 |
exec(code, global_vars, local_vars)
|
|
@@ -40,8 +39,11 @@ print("Broadcast Multiplication:\\n", tensor_broadcast_mul)
|
|
| 40 |
|
| 41 |
# Button to execute the code
|
| 42 |
if st.button("Run Code"):
|
|
|
|
|
|
|
|
|
|
| 43 |
# Execute the code and capture the output
|
| 44 |
-
output, variables = execute_code(
|
| 45 |
|
| 46 |
# Display the output
|
| 47 |
st.subheader('Output')
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
import io
|
| 3 |
import sys
|
| 4 |
|
|
|
|
| 8 |
old_stdout = sys.stdout
|
| 9 |
sys.stdout = mystdout = io.StringIO()
|
| 10 |
|
| 11 |
+
global_vars = {"torch": torch}
|
| 12 |
local_vars = {}
|
| 13 |
try:
|
| 14 |
exec(code, global_vars, local_vars)
|
|
|
|
| 39 |
|
| 40 |
# Button to execute the code
|
| 41 |
if st.button("Run Code"):
|
| 42 |
+
# Prepend the import statement
|
| 43 |
+
code_to_run = "import torch\n" + code_input
|
| 44 |
+
|
| 45 |
# Execute the code and capture the output
|
| 46 |
+
output, variables = execute_code(code_to_run)
|
| 47 |
|
| 48 |
# Display the output
|
| 49 |
st.subheader('Output')
|