Sephfox commited on
Commit
fce2463
·
verified ·
1 Parent(s): a841a36

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -21
app.py CHANGED
@@ -241,7 +241,7 @@ st.title("Advanced Cell Evolution Simulation")
241
 
242
  num_steps = st.slider("Number of simulation steps", 100, 2000, 1000)
243
  initial_cells = st.slider("Initial number of cells", 10, 200, 100)
244
- update_interval = st.slider("Update interval (milliseconds)", 50, 500, 100)
245
 
246
  if st.button("Run Simulation"):
247
  env = Environment(100, 100)
@@ -255,31 +255,36 @@ if st.button("Run Simulation"):
255
  fig = setup_figure(env)
256
  chart = st.plotly_chart(fig, use_container_width=True)
257
 
 
 
 
258
  # Run simulation
259
  for step in range(num_steps):
260
  env.update()
261
 
262
- # Update the figure data
263
- with fig.batch_update():
264
- cell_data, population_history = env.get_visualization_data()
265
- for i, (cell_type, data) in enumerate(cell_data.items()):
266
- fig.data[i].x = data["x"]
267
- fig.data[i].y = data["y"]
268
- fig.data[i].marker.size = data["size"]
 
 
 
 
 
 
 
 
 
269
 
270
- for i, (cell_type, counts) in enumerate(population_history.items()):
271
- fig.data[i+5].y = counts # +5 because we have 5 cell types in the first subplot
272
- if cell_type != "modified" and cell_type != "plant_like":
273
- fig.data[i+10].y = counts # Update individual population charts
274
- else:
275
- fig.data[13].y = population_history["plant_like"]
276
- fig.data[14].y = population_history["modified"]
277
-
278
- fig.layout.title.text = f"Advanced Cell Evolution Simulation (Time: {env.time})"
279
-
280
- # Update the chart
281
- chart.plotly_chart(fig, use_container_width=True)
282
 
283
- time.sleep(update_interval / 1000) # Convert milliseconds to seconds
 
284
 
285
  st.write("Simulation complete!")
 
241
 
242
  num_steps = st.slider("Number of simulation steps", 100, 2000, 1000)
243
  initial_cells = st.slider("Initial number of cells", 10, 200, 100)
244
+ update_interval = st.slider("Update interval (steps)", 1, 50, 10)
245
 
246
  if st.button("Run Simulation"):
247
  env = Environment(100, 100)
 
255
  fig = setup_figure(env)
256
  chart = st.plotly_chart(fig, use_container_width=True)
257
 
258
+ # Create a progress bar
259
+ progress_bar = st.progress(0)
260
+
261
  # Run simulation
262
  for step in range(num_steps):
263
  env.update()
264
 
265
+ # Update the figure data and chart less frequently
266
+ if step % update_interval == 0 or step == num_steps - 1:
267
+ with fig.batch_update():
268
+ cell_data, population_history = env.get_visualization_data()
269
+ for i, (cell_type, data) in enumerate(cell_data.items()):
270
+ fig.data[i].x = data["x"]
271
+ fig.data[i].y = data["y"]
272
+ fig.data[i].marker.size = data["size"]
273
+
274
+ for i, (cell_type, counts) in enumerate(population_history.items()):
275
+ fig.data[i+5].y = counts # +5 because we have 5 cell types in the first subplot
276
+ if cell_type != "modified" and cell_type != "plant_like":
277
+ fig.data[i+10].y = counts # Update individual population charts
278
+ else:
279
+ fig.data[13].y = population_history["plant_like"]
280
+ fig.data[14].y = population_history["modified"]
281
 
282
+ fig.layout.title.text = f"Advanced Cell Evolution Simulation (Time: {env.time})"
283
+
284
+ # Update the chart
285
+ chart.plotly_chart(fig, use_container_width=True)
 
 
 
 
 
 
 
 
286
 
287
+ # Update progress bar
288
+ progress_bar.progress((step + 1) / num_steps)
289
 
290
  st.write("Simulation complete!")