Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,21 +7,22 @@ import os
|
|
7 |
from datetime import datetime
|
8 |
from streamlit_flow import streamlit_flow
|
9 |
from streamlit_flow.elements import StreamlitFlowNode, StreamlitFlowEdge
|
10 |
-
from streamlit_flow.layouts import TreeLayout
|
11 |
|
12 |
-
#
|
13 |
Site_Name = '๐ฆCatRider๐'
|
14 |
-
title
|
15 |
-
helpURL
|
16 |
-
bugURL
|
17 |
-
icons
|
18 |
|
19 |
-
useConfig
|
20 |
-
if useConfig:
|
21 |
st.set_page_config(
|
22 |
page_title=title,
|
23 |
page_icon=icons,
|
24 |
layout="wide",
|
|
|
25 |
initial_sidebar_state="auto",
|
26 |
menu_items={
|
27 |
'Get Help': helpURL,
|
@@ -30,6 +31,7 @@ if useConfig:
|
|
30 |
}
|
31 |
)
|
32 |
|
|
|
33 |
# ๐ฑ Cat Rider and Gear Data
|
34 |
CAT_RIDERS = [
|
35 |
{"name": "Whiskers", "type": "Speed", "emoji": "๐พ", "strength": 3, "skill": 7},
|
@@ -168,13 +170,14 @@ def update_character_stats(game_state, outcome):
|
|
168 |
return game_state
|
169 |
|
170 |
# ๐ณ Journey Visualization
|
171 |
-
def
|
172 |
nodes = []
|
173 |
edges = []
|
174 |
node_ids = {}
|
175 |
for index, row in history_df.iterrows():
|
176 |
-
situation_node_id = f"situation_{row['situation_id']}"
|
177 |
-
action_node_id = f"action_{index}"
|
|
|
178 |
|
179 |
# Situation node
|
180 |
if situation_node_id not in node_ids:
|
@@ -183,44 +186,66 @@ def create_knowledge_graph(history_df):
|
|
183 |
pos=(0, 0),
|
184 |
data={'content': f"{row['situation_emoji']} {row['situation_name']}"},
|
185 |
type='default',
|
|
|
|
|
186 |
shape='ellipse'
|
187 |
)
|
188 |
nodes.append(situation_node)
|
189 |
node_ids[situation_node_id] = situation_node_id
|
190 |
|
191 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
outcome_content = 'โ
Success' if row['outcome'] else 'โ Failure'
|
193 |
stars = 'โญ' * int(row['score'])
|
194 |
-
|
195 |
-
|
196 |
pos=(0, 0),
|
197 |
-
data={'content': f"{row['
|
198 |
type='default',
|
199 |
-
|
|
|
|
|
200 |
)
|
201 |
-
nodes.append(
|
202 |
|
203 |
-
#
|
204 |
edges.append(StreamlitFlowEdge(
|
205 |
-
id=f"edge_{situation_node_id}_{action_node_id}",
|
206 |
source=situation_node_id,
|
207 |
target=action_node_id,
|
208 |
animated=True
|
209 |
))
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
|
211 |
return nodes, edges
|
212 |
|
213 |
# ๐ Markdown Preview with Subpoints for Each Action
|
214 |
def create_markdown_preview(history_df):
|
215 |
markdown = "## ๐ณ Journey Preview\n\n"
|
216 |
-
grouped = history_df.groupby(['situation_name'], sort=False)
|
217 |
|
218 |
-
for situation_name, group in grouped:
|
219 |
-
markdown += f"### {group.iloc[0]['situation_emoji']} **{situation_name}
|
220 |
for _, row in group.iterrows():
|
221 |
outcome_str = 'โ
Success' if row['outcome'] else 'โ Failure'
|
222 |
stars = 'โญ' * int(row['score'])
|
223 |
-
markdown += f"-
|
224 |
markdown += f" - {row['conclusion']}\n"
|
225 |
markdown += "\n"
|
226 |
return markdown
|
@@ -429,9 +454,9 @@ def main():
|
|
429 |
# ๐ Display Markdown Preview
|
430 |
st.markdown(create_markdown_preview(game_state['history_df']))
|
431 |
|
432 |
-
# ๐ณ Display
|
433 |
-
st.markdown("## ๐ณ Your Journey (
|
434 |
-
nodes, edges =
|
435 |
try:
|
436 |
streamlit_flow('cat_rider_flow',
|
437 |
nodes,
|
@@ -470,4 +495,3 @@ def main():
|
|
470 |
|
471 |
if __name__ == "__main__":
|
472 |
main()
|
473 |
-
|
|
|
7 |
from datetime import datetime
|
8 |
from streamlit_flow import streamlit_flow
|
9 |
from streamlit_flow.elements import StreamlitFlowNode, StreamlitFlowEdge
|
10 |
+
from streamlit_flow.layouts import TreeLayout
|
11 |
|
12 |
+
# 1. Configuration
|
13 |
Site_Name = '๐ฆCatRider๐'
|
14 |
+
title="๐ฆCatRider๐by๐คAaron Wacker"
|
15 |
+
helpURL='https://huggingface.co/awacke1'
|
16 |
+
bugURL='https://huggingface.co/spaces/awacke1'
|
17 |
+
icons='๐ฆ'
|
18 |
|
19 |
+
useConfig=True
|
20 |
+
if useConfig: # Component code - useConfig=False should allow it to work if re-evaluating UI elements due to code modify
|
21 |
st.set_page_config(
|
22 |
page_title=title,
|
23 |
page_icon=icons,
|
24 |
layout="wide",
|
25 |
+
#initial_sidebar_state="expanded",
|
26 |
initial_sidebar_state="auto",
|
27 |
menu_items={
|
28 |
'Get Help': helpURL,
|
|
|
31 |
}
|
32 |
)
|
33 |
|
34 |
+
|
35 |
# ๐ฑ Cat Rider and Gear Data
|
36 |
CAT_RIDERS = [
|
37 |
{"name": "Whiskers", "type": "Speed", "emoji": "๐พ", "strength": 3, "skill": 7},
|
|
|
170 |
return game_state
|
171 |
|
172 |
# ๐ณ Journey Visualization
|
173 |
+
def create_heterogeneous_graph(history_df):
|
174 |
nodes = []
|
175 |
edges = []
|
176 |
node_ids = {}
|
177 |
for index, row in history_df.iterrows():
|
178 |
+
situation_node_id = f"situation_{row['situation_id']}_{row['attempt']}"
|
179 |
+
action_node_id = f"action_{row['action_id']}_{index}"
|
180 |
+
outcome_node_id = f"outcome_{index}"
|
181 |
|
182 |
# Situation node
|
183 |
if situation_node_id not in node_ids:
|
|
|
186 |
pos=(0, 0),
|
187 |
data={'content': f"{row['situation_emoji']} {row['situation_name']}"},
|
188 |
type='default',
|
189 |
+
sourcePosition='bottom',
|
190 |
+
targetPosition='top',
|
191 |
shape='ellipse'
|
192 |
)
|
193 |
nodes.append(situation_node)
|
194 |
node_ids[situation_node_id] = situation_node_id
|
195 |
|
196 |
+
# Action node
|
197 |
+
action_node = StreamlitFlowNode(
|
198 |
+
action_node_id,
|
199 |
+
pos=(0, 0),
|
200 |
+
data={'content': f"{row['action_emoji']} {row['action_name']}"},
|
201 |
+
type='default',
|
202 |
+
sourcePosition='bottom',
|
203 |
+
targetPosition='top',
|
204 |
+
shape='ellipse'
|
205 |
+
)
|
206 |
+
nodes.append(action_node)
|
207 |
+
|
208 |
+
# Outcome node with success celebration
|
209 |
outcome_content = 'โ
Success' if row['outcome'] else 'โ Failure'
|
210 |
stars = 'โญ' * int(row['score'])
|
211 |
+
outcome_node = StreamlitFlowNode(
|
212 |
+
outcome_node_id,
|
213 |
pos=(0, 0),
|
214 |
+
data={'content': f"{row['conclusion']}\n{outcome_content}\n{stars}"},
|
215 |
type='default',
|
216 |
+
sourcePosition='bottom',
|
217 |
+
targetPosition='top',
|
218 |
+
shape='ellipse'
|
219 |
)
|
220 |
+
nodes.append(outcome_node)
|
221 |
|
222 |
+
# Edges
|
223 |
edges.append(StreamlitFlowEdge(
|
224 |
+
id=f"edge_{situation_node_id}_{action_node_id}_{index}",
|
225 |
source=situation_node_id,
|
226 |
target=action_node_id,
|
227 |
animated=True
|
228 |
))
|
229 |
+
edges.append(StreamlitFlowEdge(
|
230 |
+
id=f"edge_{action_node_id}_{outcome_node_id}_{index}",
|
231 |
+
source=action_node_id,
|
232 |
+
target=outcome_node_id,
|
233 |
+
animated=True
|
234 |
+
))
|
235 |
|
236 |
return nodes, edges
|
237 |
|
238 |
# ๐ Markdown Preview with Subpoints for Each Action
|
239 |
def create_markdown_preview(history_df):
|
240 |
markdown = "## ๐ณ Journey Preview\n\n"
|
241 |
+
grouped = history_df.groupby(['situation_name', 'attempt'], sort=False)
|
242 |
|
243 |
+
for (situation_name, attempt), group in grouped:
|
244 |
+
markdown += f"### {group.iloc[0]['situation_emoji']} **{situation_name}** (Attempt {attempt})\n"
|
245 |
for _, row in group.iterrows():
|
246 |
outcome_str = 'โ
Success' if row['outcome'] else 'โ Failure'
|
247 |
stars = 'โญ' * int(row['score'])
|
248 |
+
markdown += f"- {row['action_emoji']} **{row['action_name']}**: {outcome_str} {stars}\n"
|
249 |
markdown += f" - {row['conclusion']}\n"
|
250 |
markdown += "\n"
|
251 |
return markdown
|
|
|
454 |
# ๐ Display Markdown Preview
|
455 |
st.markdown(create_markdown_preview(game_state['history_df']))
|
456 |
|
457 |
+
# ๐ณ Display Heterogeneous Journey Graph
|
458 |
+
st.markdown("## ๐ณ Your Journey (Heterogeneous Graph)")
|
459 |
+
nodes, edges = create_heterogeneous_graph(game_state['history_df'])
|
460 |
try:
|
461 |
streamlit_flow('cat_rider_flow',
|
462 |
nodes,
|
|
|
495 |
|
496 |
if __name__ == "__main__":
|
497 |
main()
|
|