Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -147,14 +147,13 @@ def update_character_stats(game_state, outcome):
|
|
| 147 |
return game_state
|
| 148 |
|
| 149 |
# π³ Journey Visualization
|
| 150 |
-
def
|
| 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_{
|
| 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 |
-
#
|
| 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 |
-
|
| 189 |
-
|
| 190 |
pos=(0, 0),
|
| 191 |
-
data={'content': f"{row['
|
| 192 |
type='default',
|
| 193 |
-
|
| 194 |
-
targetPosition='top',
|
| 195 |
-
shape='ellipse'
|
| 196 |
)
|
| 197 |
-
nodes.append(
|
| 198 |
|
| 199 |
-
#
|
| 200 |
edges.append(StreamlitFlowEdge(
|
| 201 |
-
id=f"edge_{situation_node_id}_{action_node_id}
|
| 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'
|
| 219 |
|
| 220 |
-
for
|
| 221 |
-
markdown += f"### {group.iloc[0]['situation_emoji']} **{situation_name}
|
| 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
|
| 435 |
-
st.markdown("## π³ Your Journey (
|
| 436 |
-
nodes, edges =
|
| 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,
|