eaglelandsonce commited on
Commit
e6a8916
·
verified ·
1 Parent(s): b8a2a65

Update pages/3_WithExercises.py

Browse files
Files changed (1) hide show
  1. pages/3_WithExercises.py +6 -7
pages/3_WithExercises.py CHANGED
@@ -22,7 +22,7 @@ def execute_code(code):
22
 
23
  return output, local_vars
24
 
25
-
26
  exercises = {
27
  "Exercise 1: Create and Manipulate Tensors": {
28
  "description": "Tensors are the core data structure in PyTorch, similar to arrays in NumPy but with additional capabilities for GPU acceleration. This exercise introduces how to create tensors from various data sources such as lists and NumPy arrays. It also covers basic tensor operations like addition, subtraction, and element-wise multiplication, which are fundamental for manipulating data in PyTorch.",
@@ -364,7 +364,7 @@ code_input = st.text_area("Enter your PyTorch code here", height=300, value=exer
364
  # Button to execute the code
365
  if st.button("Run Code"):
366
  # Prepend the import statement
367
- code_to_run = "import torch" + code_input
368
 
369
  # Execute the code and capture the output
370
  output, variables = execute_code(code_to_run)
@@ -374,8 +374,7 @@ if st.button("Run Code"):
374
  st.text(output)
375
 
376
  # Display returned variables
377
- #if variables:
378
- #st.subheader('Variables')
379
- #for key, value in variables.items():
380
- #st.text(f"{key}: {value}")
381
-
 
22
 
23
  return output, local_vars
24
 
25
+ # Dictionary with exercise details
26
  exercises = {
27
  "Exercise 1: Create and Manipulate Tensors": {
28
  "description": "Tensors are the core data structure in PyTorch, similar to arrays in NumPy but with additional capabilities for GPU acceleration. This exercise introduces how to create tensors from various data sources such as lists and NumPy arrays. It also covers basic tensor operations like addition, subtraction, and element-wise multiplication, which are fundamental for manipulating data in PyTorch.",
 
364
  # Button to execute the code
365
  if st.button("Run Code"):
366
  # Prepend the import statement
367
+ code_to_run = "import torch\n" + code_input
368
 
369
  # Execute the code and capture the output
370
  output, variables = execute_code(code_to_run)
 
374
  st.text(output)
375
 
376
  # Display returned variables
377
+ if variables:
378
+ st.subheader('Variables')
379
+ for key, value in variables.items():
380
+ st.text(f"{key}: {value}")