eaglelandsonce commited on
Commit
43a9cc3
·
verified ·
1 Parent(s): c45ad14

Create 2_CodeSimulator.py

Browse files
Files changed (1) hide show
  1. pages/2_CodeSimulator.py +27 -0
pages/2_CodeSimulator.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import torch
3
+
4
+ # Function to execute the input code
5
+ def execute_code(code):
6
+ global_vars = {}
7
+ local_vars = {}
8
+ exec(code, global_vars, local_vars)
9
+ return local_vars
10
+
11
+ st.title('PyTorch Code Runner')
12
+
13
+ # Text area for inputting the PyTorch code
14
+ code_input = st.text_area("Enter your PyTorch code here", height=300)
15
+
16
+ # Button to execute the code
17
+ if st.button("Run Code"):
18
+ try:
19
+ # Execute the code
20
+ output = execute_code(code_input)
21
+
22
+ # Display the output
23
+ st.subheader('Output')
24
+ for key, value in output.items():
25
+ st.text(f"{key}: {value}")
26
+ except Exception as e:
27
+ st.error(f"Error: {e}")