awacke1 commited on
Commit
cd1dc69
Β·
verified Β·
1 Parent(s): 6ab7e68

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -41
app.py CHANGED
@@ -147,14 +147,13 @@ def update_character_stats(game_state, outcome):
147
  return game_state
148
 
149
  # 🌳 Journey Visualization
150
- def create_heterogeneous_graph(history_df):
151
  nodes = []
152
  edges = []
153
  node_ids = {}
154
  for index, row in history_df.iterrows():
155
- situation_node_id = f"situation_{row['situation_id']}_{row['attempt']}"
156
- action_node_id = f"action_{row['action_id']}_{index}"
157
- outcome_node_id = f"outcome_{index}"
158
 
159
  # Situation node
160
  if situation_node_id not in node_ids:
@@ -163,66 +162,44 @@ def create_heterogeneous_graph(history_df):
163
  pos=(0, 0),
164
  data={'content': f"{row['situation_emoji']} {row['situation_name']}"},
165
  type='default',
166
- sourcePosition='bottom',
167
- targetPosition='top',
168
  shape='ellipse'
169
  )
170
  nodes.append(situation_node)
171
  node_ids[situation_node_id] = situation_node_id
172
 
173
- # Action node
174
- action_node = StreamlitFlowNode(
175
- action_node_id,
176
- pos=(0, 0),
177
- data={'content': f"{row['action_emoji']} {row['action_name']}"},
178
- type='default',
179
- sourcePosition='bottom',
180
- targetPosition='top',
181
- shape='ellipse'
182
- )
183
- nodes.append(action_node)
184
-
185
- # Outcome node with success celebration
186
  outcome_content = 'βœ… Success' if row['outcome'] else '❌ Failure'
187
  stars = '⭐' * int(row['score'])
188
- outcome_node = StreamlitFlowNode(
189
- outcome_node_id,
190
  pos=(0, 0),
191
- data={'content': f"{row['conclusion']}\n{outcome_content}\n{stars}"},
192
  type='default',
193
- sourcePosition='bottom',
194
- targetPosition='top',
195
- shape='ellipse'
196
  )
197
- nodes.append(outcome_node)
198
 
199
- # Edges
200
  edges.append(StreamlitFlowEdge(
201
- id=f"edge_{situation_node_id}_{action_node_id}_{index}",
202
  source=situation_node_id,
203
  target=action_node_id,
204
  animated=True
205
  ))
206
- edges.append(StreamlitFlowEdge(
207
- id=f"edge_{action_node_id}_{outcome_node_id}_{index}",
208
- source=action_node_id,
209
- target=outcome_node_id,
210
- animated=True
211
- ))
212
 
213
  return nodes, edges
214
 
215
  # πŸ“ Markdown Preview with Subpoints for Each Action
216
  def create_markdown_preview(history_df):
217
  markdown = "## 🌳 Journey Preview\n\n"
218
- grouped = history_df.groupby(['situation_name', 'attempt'], sort=False)
219
 
220
- for (situation_name, attempt), group in grouped:
221
- markdown += f"### {group.iloc[0]['situation_emoji']} **{situation_name}** (Attempt {attempt})\n"
222
  for _, row in group.iterrows():
223
  outcome_str = 'βœ… Success' if row['outcome'] else '❌ Failure'
224
  stars = '⭐' * int(row['score'])
225
- markdown += f"- {row['action_emoji']} **{row['action_name']}**: {outcome_str} {stars}\n"
226
  markdown += f" - {row['conclusion']}\n"
227
  markdown += "\n"
228
  return markdown
@@ -431,9 +408,9 @@ def main():
431
  # πŸ“ Display Markdown Preview
432
  st.markdown(create_markdown_preview(game_state['history_df']))
433
 
434
- # 🌳 Display Heterogeneous Journey Graph
435
- st.markdown("## 🌳 Your Journey (Heterogeneous Graph)")
436
- nodes, edges = create_heterogeneous_graph(game_state['history_df'])
437
  try:
438
  streamlit_flow('cat_rider_flow',
439
  nodes,
 
147
  return game_state
148
 
149
  # 🌳 Journey Visualization
150
+ def create_knowledge_graph(history_df):
151
  nodes = []
152
  edges = []
153
  node_ids = {}
154
  for index, row in history_df.iterrows():
155
+ situation_node_id = f"situation_{row['situation_id']}"
156
+ action_node_id = f"action_{index}"
 
157
 
158
  # Situation node
159
  if situation_node_id not in node_ids:
 
162
  pos=(0, 0),
163
  data={'content': f"{row['situation_emoji']} {row['situation_name']}"},
164
  type='default',
 
 
165
  shape='ellipse'
166
  )
167
  nodes.append(situation_node)
168
  node_ids[situation_node_id] = situation_node_id
169
 
170
+ # Attempt node (action and outcome)
 
 
 
 
 
 
 
 
 
 
 
 
171
  outcome_content = 'βœ… Success' if row['outcome'] else '❌ Failure'
172
  stars = '⭐' * int(row['score'])
173
+ attempt_node = StreamlitFlowNode(
174
+ action_node_id,
175
  pos=(0, 0),
176
+ data={'content': f"{row['action_emoji']} {row['action_name']} ({outcome_content})\n{row['conclusion']}\n{stars}"},
177
  type='default',
178
+ shape='rectangle'
 
 
179
  )
180
+ nodes.append(attempt_node)
181
 
182
+ # Edge from situation to attempt
183
  edges.append(StreamlitFlowEdge(
184
+ id=f"edge_{situation_node_id}_{action_node_id}",
185
  source=situation_node_id,
186
  target=action_node_id,
187
  animated=True
188
  ))
 
 
 
 
 
 
189
 
190
  return nodes, edges
191
 
192
  # πŸ“ Markdown Preview with Subpoints for Each Action
193
  def create_markdown_preview(history_df):
194
  markdown = "## 🌳 Journey Preview\n\n"
195
+ grouped = history_df.groupby(['situation_name'], sort=False)
196
 
197
+ for situation_name, group in grouped:
198
+ markdown += f"### {group.iloc[0]['situation_emoji']} **{situation_name}**\n"
199
  for _, row in group.iterrows():
200
  outcome_str = 'βœ… Success' if row['outcome'] else '❌ Failure'
201
  stars = '⭐' * int(row['score'])
202
+ markdown += f"- Attempt {row['attempt']}: {row['action_emoji']} **{row['action_name']}**: {outcome_str} {stars}\n"
203
  markdown += f" - {row['conclusion']}\n"
204
  markdown += "\n"
205
  return markdown
 
408
  # πŸ“ Display Markdown Preview
409
  st.markdown(create_markdown_preview(game_state['history_df']))
410
 
411
+ # 🌳 Display Knowledge Journey Graph
412
+ st.markdown("## 🌳 Your Journey (Knowledge Graph)")
413
+ nodes, edges = create_knowledge_graph(game_state['history_df'])
414
  try:
415
  streamlit_flow('cat_rider_flow',
416
  nodes,