Update app.py
Browse files
app.py
CHANGED
@@ -275,21 +275,8 @@ event_log_text = st.sidebar.empty()
|
|
275 |
# Create placeholders for the chart
|
276 |
chart_placeholder = st.empty()
|
277 |
|
278 |
-
import streamlit as st
|
279 |
-
import time
|
280 |
-
from collections import deque
|
281 |
-
import threading
|
282 |
-
|
283 |
-
# ... (keep all the imports and class definitions)
|
284 |
-
|
285 |
-
# ... (keep all the function definitions)
|
286 |
|
287 |
-
# Streamlit app
|
288 |
-
st.title("Continuous Cell Evolution Simulation")
|
289 |
-
|
290 |
-
# ... (keep all the sidebar controls and placeholders)
|
291 |
|
292 |
-
# Initialize session state
|
293 |
if 'running' not in st.session_state:
|
294 |
st.session_state.running = False
|
295 |
if 'total_merges' not in st.session_state:
|
@@ -323,31 +310,24 @@ with col2:
|
|
323 |
# Main simulation loop
|
324 |
simulation_container = st.empty()
|
325 |
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
st.session_state.env.update()
|
333 |
-
final_cell_count = len(st.session_state.env.cells)
|
334 |
-
|
335 |
-
# Check for merges
|
336 |
-
if final_cell_count < initial_cell_count:
|
337 |
-
merges = initial_cell_count - final_cell_count
|
338 |
-
st.session_state.total_merges += merges
|
339 |
-
event_log.appendleft(f"Time {st.session_state.env.time}: {merges} cell merges occurred")
|
340 |
-
|
341 |
-
update_chart()
|
342 |
-
update_statistics()
|
343 |
|
344 |
-
|
|
|
|
|
|
|
|
|
345 |
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
|
352 |
if not st.session_state.running:
|
353 |
st.write("Simulation stopped. Click 'Start Simulation' to run again.")
|
|
|
275 |
# Create placeholders for the chart
|
276 |
chart_placeholder = st.empty()
|
277 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
278 |
|
|
|
|
|
|
|
|
|
279 |
|
|
|
280 |
if 'running' not in st.session_state:
|
281 |
st.session_state.running = False
|
282 |
if 'total_merges' not in st.session_state:
|
|
|
310 |
# Main simulation loop
|
311 |
simulation_container = st.empty()
|
312 |
|
313 |
+
if st.session_state.running and st.session_state.env is not None:
|
314 |
+
with simulation_container.container():
|
315 |
+
for _ in range(4): # Update 4 times per frame to increase simulation speed
|
316 |
+
initial_cell_count = len(st.session_state.env.cells)
|
317 |
+
st.session_state.env.update()
|
318 |
+
final_cell_count = len(st.session_state.env.cells)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
319 |
|
320 |
+
# Check for merges
|
321 |
+
if final_cell_count < initial_cell_count:
|
322 |
+
merges = initial_cell_count - final_cell_count
|
323 |
+
st.session_state.total_merges += merges
|
324 |
+
event_log.appendleft(f"Time {st.session_state.env.time}: {merges} cell merges occurred")
|
325 |
|
326 |
+
update_chart()
|
327 |
+
update_statistics()
|
328 |
+
|
329 |
+
time.sleep(update_interval)
|
330 |
+
st.experimental_rerun()
|
331 |
|
332 |
if not st.session_state.running:
|
333 |
st.write("Simulation stopped. Click 'Start Simulation' to run again.")
|