Sephfox commited on
Commit
5e7860c
·
verified ·
1 Parent(s): 2ff6f00

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -12
app.py CHANGED
@@ -7,6 +7,17 @@ import time
7
  from collections import deque # Add this line
8
  import threading
9
 
 
 
 
 
 
 
 
 
 
 
 
10
  class Organelle:
11
  def __init__(self, type):
12
  self.type = type
@@ -244,6 +255,10 @@ def update_chart():
244
  # Clear existing traces
245
  st.session_state.fig.data = []
246
 
 
 
 
 
247
  # Cell positions
248
  cell_types = [cell.cell_type for cell in st.session_state.env.cells]
249
  x_positions = [cell.x for cell in st.session_state.env.cells]
@@ -285,25 +300,31 @@ def update_chart():
285
 
286
  st.session_state.fig.update_layout(height=800, width=1200, title_text="Advanced Cell Evolution Simulation")
287
 
288
- # Update the chart placeholder
 
 
 
 
 
289
  chart_placeholder.plotly_chart(st.session_state.fig)
290
 
291
  def start_simulation():
292
  st.session_state.running = True
293
  if st.session_state.env is None:
 
 
 
 
 
 
294
  st.session_state.env = Environment(100, 100, effects)
295
- for _ in range(initial_cells):
296
- cell = Cell(random.uniform(0, st.session_state.env.width), random.uniform(0, st.session_state.env.height))
 
297
  st.session_state.env.add_cell(cell)
298
- st.session_state.fig = go.Figure(layout=go.Layout(
299
- height=800, width=1200,
300
- title='Advanced Cell Evolution Simulation',
301
- showlegend=True,
302
- ))
303
- # Set up subplots
304
- st.session_state.fig = make_subplots(rows=2, cols=2,
305
- subplot_titles=('Cell Positions', 'Population History',
306
- 'Population by Cell Type', 'Organelle Distribution'))
307
 
308
  def stop_simulation():
309
  st.session_state.running = False
 
7
  from collections import deque # Add this line
8
  import threading
9
 
10
+
11
+ # Initialize session state variables
12
+ if 'running' not in st.session_state:
13
+ st.session_state.running = False
14
+
15
+ if 'env' not in st.session_state:
16
+ st.session_state.env = None
17
+
18
+ if 'fig' not in st.session_state:
19
+ st.session_state.fig = None
20
+
21
  class Organelle:
22
  def __init__(self, type):
23
  self.type = type
 
255
  # Clear existing traces
256
  st.session_state.fig.data = []
257
 
258
+ if st.session_state.running and st.session_state.env is not None:
259
+ st.session_state.env.update()
260
+ update_chart()
261
+
262
  # Cell positions
263
  cell_types = [cell.cell_type for cell in st.session_state.env.cells]
264
  x_positions = [cell.x for cell in st.session_state.env.cells]
 
300
 
301
  st.session_state.fig.update_layout(height=800, width=1200, title_text="Advanced Cell Evolution Simulation")
302
 
303
+ st.sidebar.header("Simulation Settings")
304
+ st.session_state.radiation = st.sidebar.checkbox("Enable Radiation", value=False)
305
+ st.session_state.predation = st.sidebar.checkbox("Enable Predation", value=False)
306
+ st.session_state.symbiosis = st.sidebar.checkbox("Enable Symbiosis", value=False)
307
+
308
+ # Update the chart placeholder
309
  chart_placeholder.plotly_chart(st.session_state.fig)
310
 
311
  def start_simulation():
312
  st.session_state.running = True
313
  if st.session_state.env is None:
314
+ # Initialize your environment here
315
+ effects = {
316
+ 'radiation': st.session_state.radiation,
317
+ 'predation': st.session_state.predation,
318
+ 'symbiosis': st.session_state.symbiosis
319
+ }
320
  st.session_state.env = Environment(100, 100, effects)
321
+ # Add initial cells to the environment
322
+ for _ in range(50):
323
+ cell = Cell(random.uniform(0, 100), random.uniform(0, 100))
324
  st.session_state.env.add_cell(cell)
325
+
326
+ if st.session_state.fig is None:
327
+ st.session_state.fig = setup_figure(st.session_state.env)
 
 
 
 
 
 
328
 
329
  def stop_simulation():
330
  st.session_state.running = False