awacke1 commited on
Commit
26b53ab
Β·
verified Β·
1 Parent(s): cd1dc69

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +190 -1
README.md CHANGED
@@ -10,4 +10,193 @@ pinned: false
10
  license: mit
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  license: mit
11
  ---
12
 
13
+ Explanation of Updates:
14
+ Renamed the Graph Function and Title:
15
+
16
+ Renamed the function create_heterogeneous_graph to create_knowledge_graph to match your request.
17
+ Changed the display title from "Your Journey (Heterogeneous Graph)" to "Your Journey (Knowledge Graph)".
18
+ Adjusted the function calls in the main application to reflect the new function name.
19
+ Modified the Graph Structure in create_knowledge_graph:
20
+
21
+ Situation Nodes:
22
+
23
+ Each unique situation is represented by a single node.
24
+ Created a node for each situation only once by checking if the situation node ID is already in node_ids.
25
+ Attempt Nodes:
26
+
27
+ For each action (attempt), created a child node under the corresponding situation node.
28
+ The attempt node includes the action, outcome, conclusion, and stars reflecting the score.
29
+ Edges:
30
+
31
+ Created an edge from the situation node to each attempt node.
32
+ This results in a tree structure under each situation node showing all attempts.
33
+ python
34
+ Copy code
35
+ def create_knowledge_graph(history_df):
36
+ nodes = []
37
+ edges = []
38
+ node_ids = {}
39
+ for index, row in history_df.iterrows():
40
+ situation_node_id = f"situation_{row['situation_id']}"
41
+ action_node_id = f"action_{index}"
42
+
43
+ # Situation node
44
+ if situation_node_id not in node_ids:
45
+ situation_node = StreamlitFlowNode(
46
+ situation_node_id,
47
+ pos=(0, 0),
48
+ data={'content': f"{row['situation_emoji']} {row['situation_name']}"},
49
+ type='default',
50
+ shape='ellipse'
51
+ )
52
+ nodes.append(situation_node)
53
+ node_ids[situation_node_id] = situation_node_id
54
+
55
+ # Attempt node (action and outcome)
56
+ outcome_content = 'βœ… Success' if row['outcome'] else '❌ Failure'
57
+ stars = '⭐' * int(row['score'])
58
+ attempt_node = StreamlitFlowNode(
59
+ action_node_id,
60
+ pos=(0, 0),
61
+ data={'content': f"{row['action_emoji']} {row['action_name']} ({outcome_content})\n{row['conclusion']}\n{stars}"},
62
+ type='default',
63
+ shape='rectangle'
64
+ )
65
+ nodes.append(attempt_node)
66
+
67
+ # Edge from situation to attempt
68
+ edges.append(StreamlitFlowEdge(
69
+ id=f"edge_{situation_node_id}_{action_node_id}",
70
+ source=situation_node_id,
71
+ target=action_node_id,
72
+ animated=True
73
+ ))
74
+
75
+ return nodes, edges
76
+ Updated the Markdown Preview in create_markdown_preview:
77
+
78
+ Modified the markdown structure to group attempts under each unique situation, regardless of the attempt number.
79
+ The output now matches the format you provided, showing multiple attempts per situation.
80
+ python
81
+ Copy code
82
+ def create_markdown_preview(history_df):
83
+ markdown = "## 🌳 Journey Preview\n\n"
84
+ grouped = history_df.groupby(['situation_name'], sort=False)
85
+
86
+ for situation_name, group in grouped:
87
+ markdown += f"### {group.iloc[0]['situation_emoji']} **{situation_name}**\n"
88
+ for _, row in group.iterrows():
89
+ outcome_str = 'βœ… Success' if row['outcome'] else '❌ Failure'
90
+ stars = '⭐' * int(row['score'])
91
+ markdown += f"- Attempt {row['attempt']}: {row['action_emoji']} **{row['action_name']}**: {outcome_str} {stars}\n"
92
+ markdown += f" - {row['conclusion']}\n"
93
+ markdown += "\n"
94
+ return markdown
95
+ Ensured the Graph Reflects the Journey Preview:
96
+
97
+ The graph now displays each unique situation once, with all attempts as child nodes.
98
+ This results in multiple trees, one for each situation, matching the three trees in your example.
99
+ Adjusted the Main Function to Reflect Changes:
100
+
101
+ Updated the function calls to use create_knowledge_graph instead of create_heterogeneous_graph.
102
+ Changed the display title accordingly.
103
+ python
104
+ Copy code
105
+ # Integration point for both functions
106
+ if not game_state['history_df'].empty:
107
+ # πŸ“ Display Markdown Preview
108
+ st.markdown(create_markdown_preview(game_state['history_df']))
109
+
110
+ # 🌳 Display Knowledge Journey Graph
111
+ st.markdown("## 🌳 Your Journey (Knowledge Graph)")
112
+ nodes, edges = create_knowledge_graph(game_state['history_df'])
113
+ try:
114
+ streamlit_flow('cat_rider_flow',
115
+ nodes,
116
+ edges,
117
+ layout=TreeLayout(direction='down'),
118
+ fit_view=True,
119
+ height=600)
120
+ except Exception as e:
121
+ st.error(f"An error occurred while rendering the journey graph: {str(e)}")
122
+ st.markdown("Please try refreshing the page if the graph doesn't appear.")
123
+ How It Now Works:
124
+ Graph Structure:
125
+
126
+ Each unique situation is a node in the graph.
127
+ All attempts (actions taken) under a situation are child nodes connected to the situation node.
128
+ Both failures and successes are displayed as child nodes.
129
+ This creates a tree structure for each situation, reflecting the multiple attempts.
130
+ Journey Preview:
131
+
132
+ The markdown preview shows the situations, with attempts listed under each.
133
+ Attempts include the action taken, outcome, score (stars), and conclusion.
134
+ The format matches the example you provided.
135
+ Multiple Trees:
136
+
137
+ If the player encounters multiple unique situations, the graph will display multiple trees.
138
+ Each tree represents a situation with its attempts.
139
+ This provides a clear visual of the player's journey through different scenarios.
140
+ Example Output:
141
+ Assuming the player has the following history:
142
+
143
+ The Great Feline Escape:
144
+
145
+ Attempt 1: Negotiate – Failure
146
+ Attempt 2: Sprint Away – Success
147
+ The Royal Tournament:
148
+
149
+ Attempt 1: Sprint Away – Success
150
+ Attempt 2: Show Bravery – Failure
151
+ Attempt 3: Negotiate – Success
152
+ The Great Cheese Heist:
153
+
154
+ Attempt 1: Develop a Strategy – Success
155
+ The graph will have three situation nodes:
156
+
157
+ The Great Feline Escape
158
+
159
+ Child Nodes:
160
+ Negotiate (Failure)
161
+ Sprint Away (Success)
162
+ The Royal Tournament
163
+
164
+ Child Nodes:
165
+ Sprint Away (Success)
166
+ Show Bravery (Failure)
167
+ Negotiate (Success)
168
+ The Great Cheese Heist
169
+
170
+ Child Nodes:
171
+ Develop a Strategy (Success)
172
+ Running the Updated Code:
173
+ Ensure Required Libraries Are Installed:
174
+
175
+ bash
176
+ Copy code
177
+ pip install streamlit pandas plotly streamlit-flow
178
+ Save the Code:
179
+
180
+ Save the updated code into a file, e.g., cat_rider_game.py.
181
+
182
+ Run the Streamlit App:
183
+
184
+ bash
185
+ Copy code
186
+ streamlit run cat_rider_game.py
187
+ Play the Game:
188
+
189
+ Choose your Cat Rider and Riding Gear.
190
+ Engage in adventures and make decisions.
191
+ View the updated Journey Preview and Knowledge Graph after each action.
192
+ Save and download your game histories via the sidebar.
193
+ Note:
194
+ If you encounter any issues with the streamlit-flow library, ensure it is correctly installed and compatible with your environment.
195
+ The code assumes that the StreamlitFlowNode and StreamlitFlowEdge classes accept the parameters as specified. If not, you may need to adjust the parameter names according to the library's documentation.
196
+ Conclusion:
197
+ This updated code reflects your requirements by:
198
+
199
+ Changing the graph to "Knowledge Graph".
200
+ Displaying each situation once in the graph, with attempts as child nodes.
201
+ Matching the Journey Preview format you provided.
202
+ Providing a clear visualization of the player's journey with multiple trees for unique situations.