YashsharmaPhD commited on
Commit
3062fb3
·
verified ·
1 Parent(s): cd6adf8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -78,7 +78,7 @@ def visualize_spike_train(spike_train, plot_container):
78
  plot_container.pyplot(fig)
79
 
80
  # Generate spikes for the given pressure value
81
- def generate_spikes_for_pressure(pressure, plot_container, duration=1):
82
  # Simulate the pressure as the input (scale to appropriate format for LSTM)
83
  # Assuming the pressure range is from 0.1 to 1.0 MPa, and normalize the value
84
  pressure_normalized = (pressure - 0.1) / (1.0 - 0.1) # Normalize between 0 and 1
@@ -96,14 +96,14 @@ def generate_spikes_for_pressure(pressure, plot_container, duration=1):
96
  # Forward pass through the model
97
  output, memory_grid = model(pressure_input)
98
 
99
- # Visualize the memory grid (4x4 grid)
100
- visualize_memory_grid(memory_grid, plot_container)
101
 
102
  # Convert the output into a spike train by thresholding the filtered output
103
  spike_train = (output.detach().numpy() > 0).astype(int) # 1 for spike, 0 for no spike
104
 
105
- # Visualize the spike train
106
- visualize_spike_train(spike_train, plot_container)
107
 
108
  # Delay to simulate real-time plotting (e.g., update every second)
109
  time.sleep(1)
@@ -119,12 +119,18 @@ def app():
119
  if st.button(f"Generate Spikes & Visualize Memory for {pressure} MPa"):
120
  st.info(f"Generating spikes for {pressure} MPa...")
121
 
122
- # Create containers for both plots
123
- memory_plot_container = st.empty()
124
- spike_train_plot_container = st.empty()
 
 
 
 
 
 
125
 
126
  # Generate spikes and memory updates for the given pressure
127
- generate_spikes_for_pressure(pressure, memory_plot_container, duration)
128
 
129
  st.success(f"Spike generation and memory passing complete for {pressure} MPa!")
130
 
 
78
  plot_container.pyplot(fig)
79
 
80
  # Generate spikes for the given pressure value
81
+ def generate_spikes_for_pressure(pressure, memory_plot_container, spike_plot_container, duration=1):
82
  # Simulate the pressure as the input (scale to appropriate format for LSTM)
83
  # Assuming the pressure range is from 0.1 to 1.0 MPa, and normalize the value
84
  pressure_normalized = (pressure - 0.1) / (1.0 - 0.1) # Normalize between 0 and 1
 
96
  # Forward pass through the model
97
  output, memory_grid = model(pressure_input)
98
 
99
+ # Visualize the memory grid (4x4 grid) on the left plot container
100
+ visualize_memory_grid(memory_grid, memory_plot_container)
101
 
102
  # Convert the output into a spike train by thresholding the filtered output
103
  spike_train = (output.detach().numpy() > 0).astype(int) # 1 for spike, 0 for no spike
104
 
105
+ # Visualize the spike train on the right plot container
106
+ visualize_spike_train(spike_train, spike_plot_container)
107
 
108
  # Delay to simulate real-time plotting (e.g., update every second)
109
  time.sleep(1)
 
119
  if st.button(f"Generate Spikes & Visualize Memory for {pressure} MPa"):
120
  st.info(f"Generating spikes for {pressure} MPa...")
121
 
122
+ # Create columns for both plots (left for memory grid, right for spike train)
123
+ col1, col2 = st.columns(2)
124
+
125
+ # Create plot containers for each column
126
+ with col1:
127
+ memory_plot_container = st.empty()
128
+
129
+ with col2:
130
+ spike_plot_container = st.empty()
131
 
132
  # Generate spikes and memory updates for the given pressure
133
+ generate_spikes_for_pressure(pressure, memory_plot_container, spike_plot_container, duration)
134
 
135
  st.success(f"Spike generation and memory passing complete for {pressure} MPa!")
136