Update app.py
Browse files
app.py
CHANGED
@@ -239,11 +239,16 @@ def setup_figure(env):
|
|
239 |
# Streamlit app
|
240 |
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 (
|
245 |
|
246 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
247 |
env = Environment(100, 100)
|
248 |
|
249 |
# Add initial cells
|
@@ -253,38 +258,38 @@ if st.button("Run Simulation"):
|
|
253 |
|
254 |
# Set up the figure
|
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 |
-
|
263 |
env.update()
|
264 |
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
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 |
-
|
285 |
-
|
|
|
|
|
|
|
|
|
|
|
286 |
|
287 |
-
|
288 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
289 |
|
290 |
-
|
|
|
|
|
|
239 |
# Streamlit app
|
240 |
st.title("Advanced Cell Evolution Simulation")
|
241 |
|
|
|
242 |
initial_cells = st.slider("Initial number of cells", 10, 200, 100)
|
243 |
+
update_interval = st.slider("Update interval (seconds)", 0.1, 5.0, 1.0)
|
244 |
|
245 |
+
# Create a placeholder for the chart
|
246 |
+
chart_placeholder = st.empty()
|
247 |
+
|
248 |
+
# Create a button to start/stop the simulation
|
249 |
+
start_button = st.button("Start Simulation")
|
250 |
+
|
251 |
+
if start_button:
|
252 |
env = Environment(100, 100)
|
253 |
|
254 |
# Add initial cells
|
|
|
258 |
|
259 |
# Set up the figure
|
260 |
fig = setup_figure(env)
|
|
|
|
|
|
|
|
|
261 |
|
262 |
# Run simulation
|
263 |
+
while True:
|
264 |
env.update()
|
265 |
|
266 |
+
with fig.batch_update():
|
267 |
+
cell_data, population_history = env.get_visualization_data()
|
268 |
+
for i, (cell_type, data) in enumerate(cell_data.items()):
|
269 |
+
fig.data[i].x = data["x"]
|
270 |
+
fig.data[i].y = data["y"]
|
271 |
+
fig.data[i].marker.size = data["size"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
272 |
|
273 |
+
for i, (cell_type, counts) in enumerate(population_history.items()):
|
274 |
+
fig.data[i+5].y = counts # +5 because we have 5 cell types in the first subplot
|
275 |
+
if cell_type != "modified" and cell_type != "plant_like":
|
276 |
+
fig.data[i+10].y = counts # Update individual population charts
|
277 |
+
else:
|
278 |
+
fig.data[13].y = population_history["plant_like"]
|
279 |
+
fig.data[14].y = population_history["modified"]
|
280 |
|
281 |
+
fig.layout.title.text = f"Advanced Cell Evolution Simulation (Time: {env.time})"
|
282 |
+
|
283 |
+
# Update the chart
|
284 |
+
chart_placeholder.plotly_chart(fig, use_container_width=True)
|
285 |
+
|
286 |
+
# Wait for the specified interval
|
287 |
+
time.sleep(update_interval)
|
288 |
+
|
289 |
+
# Check if the Streamlit script should stop
|
290 |
+
if not st.session_state.get('run_simulation', True):
|
291 |
+
break
|
292 |
|
293 |
+
# Add a button to stop the simulation
|
294 |
+
if st.button("Stop Simulation"):
|
295 |
+
st.session_state.run_simulation = False
|