Sephfox commited on
Commit
f259ff8
1 Parent(s): c508214

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -48
app.py CHANGED
@@ -134,55 +134,31 @@ class Environment:
134
  def visualize(self):
135
  fig = make_subplots(rows=1, cols=2, subplot_titles=("Cell Distribution", "Population Over Time"))
136
 
137
- # Cell distribution
138
- cell_types = set(cell.cell_type for cell in self.cells)
139
- for cell_type in cell_types:
140
- x = [cell.x for cell in self.cells if cell.cell_type == cell_type]
141
- y = [cell.y for cell in self.cells if cell.cell_type == cell_type]
142
- color = next(cell.color for cell in self.cells if cell.cell_type == cell_type)
143
- size = next(cell.size * 3 for cell in self.cells if cell.cell_type == cell_type)
144
- fig.add_trace(go.Scatter(x=x, y=y, mode='markers', marker=dict(color=color, size=size),
145
- name=cell_type), row=1, col=1)
146
-
147
- fig.update_xaxes(title_text="X", row=1, col=1)
148
- fig.update_yaxes(title_text="Y", row=1, col=1)
149
-
150
- # Population over time
151
- population_counts = {
152
- "prokaryote": [],
153
- "early_eukaryote": [],
154
- "advanced_eukaryote": [],
155
- "plant_like": []
156
- }
157
-
158
- for cell_type in population_counts:
159
- count = len([cell for cell in self.cells if cell.cell_type == cell_type])
160
- population_counts[cell_type].append(count)
161
-
162
- for cell_type, counts in population_counts.items():
163
- fig.add_trace(go.Scatter(y=counts, mode='lines', name=cell_type), row=1, col=2)
164
-
165
- fig.update_xaxes(title_text="Time", row=1, col=2)
166
- fig.update_yaxes(title_text="Population", row=1, col=2)
167
-
168
- fig.update_layout(height=600, width=1200,
169
- title_text=f"Cell Evolution Simulation (Time: {self.time})")
170
- return fig
171
-
172
- def run_simulation(num_steps, initial_cells):
173
- env = Environment(100, 100)
174
-
175
- # Add initial cells
176
- for _ in range(initial_cells):
177
- cell = Cell(random.uniform(0, env.width), random.uniform(0, env.height))
178
- env.add_cell(cell)
179
-
180
- # Run simulation
181
- for step in range(num_steps):
182
- env.update()
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)
 
134
  def visualize(self):
135
  fig = make_subplots(rows=1, cols=2, subplot_titles=("Cell Distribution", "Population Over Time"))
136
 
137
+ def setup_figure(env):
138
+ fig = make_subplots(rows=1, cols=2, subplot_titles=("Cell Distribution", "Population Over Time"))
139
+
140
+ # Cell distribution
141
+ for cell_type, data in env.get_visualization_data()[0].items():
142
+ fig.add_trace(go.Scatter(
143
+ x=data["x"], y=data["y"], mode='markers',
144
+ marker=dict(color=data["color"], size=data["size"]),
145
+ name=cell_type
146
+ ), row=1, col=1)
147
+
148
+ # Population over time
149
+ for cell_type, counts in env.population_history.items():
150
+ fig.add_trace(go.Scatter(y=counts, mode='lines', name=cell_type), row=1, col=2)
151
+
152
+ fig.update_xaxes(title_text="X", row=1, col=1)
153
+ fig.update_yaxes(title_text="Y", row=1, col=1)
154
+ fig.update_xaxes(title_text="Time", row=1, col=2)
155
+ fig.update_yaxes(title_text="Population", row=1, col=2)
156
+
157
+ fig.update_layout(height=600, width=1200, title_text="Cell Evolution Simulation")
158
+
159
+ return fig
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
 
161
+ # Streamlit app
162
  st.title("Cell Evolution Simulation")
163
 
164
  num_steps = st.slider("Number of simulation steps", 100, 1000, 500)