Sephfox commited on
Commit
c508214
1 Parent(s): 22b66c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -7
app.py CHANGED
@@ -183,20 +183,44 @@ def run_simulation(num_steps, initial_cells):
183
  if step % 10 == 0: # Visualize every 10 steps
184
  yield env.visualize()
185
 
186
- # Streamlit app
187
  st.title("Cell Evolution Simulation")
188
 
189
  num_steps = st.slider("Number of simulation steps", 100, 1000, 500)
190
  initial_cells = st.slider("Initial number of cells", 10, 100, 50)
 
191
 
192
  if st.button("Run Simulation"):
193
- simulation = run_simulation(num_steps, initial_cells)
194
 
195
- # Create a placeholder for the chart
196
- chart_placeholder = st.empty()
 
 
 
 
 
 
197
 
198
- # Update the chart for each step
199
- for chart in simulation:
200
- chart_placeholder.plotly_chart(chart, use_container_width=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
201
 
202
  st.write("Simulation complete!")
 
183
  if step % 10 == 0: # Visualize every 10 steps
184
  yield env.visualize()
185
 
 
186
  st.title("Cell Evolution Simulation")
187
 
188
  num_steps = st.slider("Number of simulation steps", 100, 1000, 500)
189
  initial_cells = st.slider("Initial number of cells", 10, 100, 50)
190
+ update_interval = st.slider("Update interval (milliseconds)", 100, 1000, 200)
191
 
192
  if st.button("Run Simulation"):
193
+ env = Environment(100, 100)
194
 
195
+ # Add initial cells
196
+ for _ in range(initial_cells):
197
+ cell = Cell(random.uniform(0, env.width), random.uniform(0, env.height))
198
+ env.add_cell(cell)
199
+
200
+ # Set up the figure
201
+ fig = setup_figure(env)
202
+ chart = st.plotly_chart(fig, use_container_width=True)
203
 
204
+ # Run simulation
205
+ for step in range(num_steps):
206
+ env.update()
207
+
208
+ # Update the figure data
209
+ with fig.batch_update():
210
+ cell_data, population_history = env.get_visualization_data()
211
+ for i, (cell_type, data) in enumerate(cell_data.items()):
212
+ fig.data[i].x = data["x"]
213
+ fig.data[i].y = data["y"]
214
+ fig.data[i].marker.size = data["size"]
215
+
216
+ for i, (cell_type, counts) in enumerate(population_history.items()):
217
+ fig.data[i+4].y = counts # +4 because we have 4 cell types in the first subplot
218
+
219
+ fig.layout.title.text = f"Cell Evolution Simulation (Time: {env.time})"
220
+
221
+ # Update the chart
222
+ chart.plotly_chart(fig, use_container_width=True)
223
+
224
+ time.sleep(update_interval / 1000) # Convert milliseconds to seconds
225
 
226
  st.write("Simulation complete!")