Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import plotly.express as px
|
@@ -8,21 +9,21 @@ import re
|
|
8 |
from datetime import datetime
|
9 |
from streamlit_flow import streamlit_flow
|
10 |
from streamlit_flow.elements import StreamlitFlowNode, StreamlitFlowEdge
|
11 |
-
from streamlit_flow.layouts import
|
12 |
|
13 |
-
#
|
14 |
Site_Name = '🦁CatRider🐈'
|
15 |
title="🦁CatRider🐈by👤Aaron Wacker"
|
16 |
helpURL='https://huggingface.co/awacke1'
|
17 |
bugURL='https://huggingface.co/spaces/awacke1'
|
18 |
icons='🦁'
|
|
|
19 |
useConfig=True
|
20 |
-
if useConfig:
|
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,
|
@@ -30,7 +31,7 @@ if useConfig: # Component code - useConfig=False should allow it to work if re-e
|
|
30 |
'About': title
|
31 |
}
|
32 |
)
|
33 |
-
|
34 |
# 🐱 Cat Rider and Gear Data
|
35 |
CAT_RIDERS = [
|
36 |
{"name": "Whiskers", "type": "Speed", "emoji": "🐾", "strength": 3, "skill": 7},
|
@@ -146,6 +147,8 @@ def parse_history_markdown(markdown_text):
|
|
146 |
stars = attempt_match.group(5)
|
147 |
outcome = True if outcome_str == '✅ Success' else False
|
148 |
score = len(stars)
|
|
|
|
|
149 |
data.append({
|
150 |
'situation_name': situation_name,
|
151 |
'situation_emoji': situation_emoji,
|
@@ -153,7 +156,8 @@ def parse_history_markdown(markdown_text):
|
|
153 |
'action_name': action_name,
|
154 |
'action_emoji': action_emoji,
|
155 |
'outcome': outcome,
|
156 |
-
'score': score
|
|
|
157 |
})
|
158 |
history_df = pd.DataFrame(data)
|
159 |
return history_df
|
@@ -215,9 +219,21 @@ def process_journey_history(history_df):
|
|
215 |
|
216 |
grouped = history_df.groupby(['situation_name'], sort=False)
|
217 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
for situation_name, group in grouped:
|
219 |
situation_emoji = group.iloc[0]['situation_emoji']
|
220 |
-
situation_id = group.iloc[0].get('situation_id', uuid.uuid4())
|
221 |
situation_node_id = f"situation_{situation_id}"
|
222 |
|
223 |
markdown += f"### {situation_emoji} **{situation_name}**\n"
|
@@ -227,14 +243,24 @@ def process_journey_history(history_df):
|
|
227 |
situation_node = StreamlitFlowNode(
|
228 |
situation_node_id,
|
229 |
pos=(0, 0),
|
230 |
-
data={'content': f"{situation_emoji} {situation_name}"},
|
231 |
type='default',
|
232 |
-
|
|
|
|
|
233 |
)
|
234 |
nodes.append(situation_node)
|
235 |
node_ids[situation_node_id] = situation_node_id
|
236 |
|
237 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
238 |
attempt = row['attempt']
|
239 |
action_emoji = row['action_emoji']
|
240 |
action_name = row['action_name']
|
@@ -247,18 +273,17 @@ def process_journey_history(history_df):
|
|
247 |
markdown += f"{conclusion}\n"
|
248 |
|
249 |
# Create attempt node
|
250 |
-
attempt_node_id = f"attempt_{situation_id}_{attempt}_{
|
251 |
-
|
252 |
-
attempt_content = f"Attempt {attempt}: {action_emoji} {action_name} - {outcome_str}\n{stars}"
|
253 |
-
else:
|
254 |
-
attempt_content = f"Attempt {attempt}: {action_emoji} {action_name} - {outcome_str}"
|
255 |
|
256 |
attempt_node = StreamlitFlowNode(
|
257 |
attempt_node_id,
|
258 |
pos=(0, 0),
|
259 |
data={'content': attempt_content},
|
260 |
-
type='
|
261 |
-
|
|
|
|
|
262 |
)
|
263 |
nodes.append(attempt_node)
|
264 |
|
@@ -493,9 +518,9 @@ def main():
|
|
493 |
streamlit_flow('cat_rider_flow',
|
494 |
nodes,
|
495 |
edges,
|
496 |
-
layout=
|
497 |
fit_view=True,
|
498 |
-
height=
|
499 |
except Exception as e:
|
500 |
st.error(f"An error occurred while rendering the journey graph: {str(e)}")
|
501 |
st.markdown("Please try refreshing the page if the graph doesn't appear.")
|
|
|
1 |
+
# 1. Configuration
|
2 |
import streamlit as st
|
3 |
import pandas as pd
|
4 |
import plotly.express as px
|
|
|
9 |
from datetime import datetime
|
10 |
from streamlit_flow import streamlit_flow
|
11 |
from streamlit_flow.elements import StreamlitFlowNode, StreamlitFlowEdge
|
12 |
+
from streamlit_flow.layouts import RadialLayout
|
13 |
|
14 |
+
# Set page configuration to wide mode
|
15 |
Site_Name = '🦁CatRider🐈'
|
16 |
title="🦁CatRider🐈by👤Aaron Wacker"
|
17 |
helpURL='https://huggingface.co/awacke1'
|
18 |
bugURL='https://huggingface.co/spaces/awacke1'
|
19 |
icons='🦁'
|
20 |
+
|
21 |
useConfig=True
|
22 |
+
if useConfig:
|
23 |
st.set_page_config(
|
24 |
page_title=title,
|
25 |
page_icon=icons,
|
26 |
layout="wide",
|
|
|
27 |
initial_sidebar_state="auto",
|
28 |
menu_items={
|
29 |
'Get Help': helpURL,
|
|
|
31 |
'About': title
|
32 |
}
|
33 |
)
|
34 |
+
|
35 |
# 🐱 Cat Rider and Gear Data
|
36 |
CAT_RIDERS = [
|
37 |
{"name": "Whiskers", "type": "Speed", "emoji": "🐾", "strength": 3, "skill": 7},
|
|
|
147 |
stars = attempt_match.group(5)
|
148 |
outcome = True if outcome_str == '✅ Success' else False
|
149 |
score = len(stars)
|
150 |
+
conclusion_line_index = lines.index(line) + 1
|
151 |
+
conclusion = lines[conclusion_line_index] if conclusion_line_index < len(lines) else ''
|
152 |
data.append({
|
153 |
'situation_name': situation_name,
|
154 |
'situation_emoji': situation_emoji,
|
|
|
156 |
'action_name': action_name,
|
157 |
'action_emoji': action_emoji,
|
158 |
'outcome': outcome,
|
159 |
+
'score': score,
|
160 |
+
'conclusion': conclusion
|
161 |
})
|
162 |
history_df = pd.DataFrame(data)
|
163 |
return history_df
|
|
|
219 |
|
220 |
grouped = history_df.groupby(['situation_name'], sort=False)
|
221 |
|
222 |
+
# Main node to connect all situations
|
223 |
+
main_node_id = "main"
|
224 |
+
main_node = StreamlitFlowNode(
|
225 |
+
main_node_id,
|
226 |
+
pos=(0, 0),
|
227 |
+
data={'content': "# Your Journey"},
|
228 |
+
type='input',
|
229 |
+
target_position='bottom',
|
230 |
+
width=200
|
231 |
+
)
|
232 |
+
nodes.append(main_node)
|
233 |
+
|
234 |
for situation_name, group in grouped:
|
235 |
situation_emoji = group.iloc[0]['situation_emoji']
|
236 |
+
situation_id = group.iloc[0].get('situation_id', str(uuid.uuid4()))
|
237 |
situation_node_id = f"situation_{situation_id}"
|
238 |
|
239 |
markdown += f"### {situation_emoji} **{situation_name}**\n"
|
|
|
243 |
situation_node = StreamlitFlowNode(
|
244 |
situation_node_id,
|
245 |
pos=(0, 0),
|
246 |
+
data={'content': f"### {situation_emoji} {situation_name}"},
|
247 |
type='default',
|
248 |
+
target_position='top',
|
249 |
+
source_position='bottom',
|
250 |
+
width=200
|
251 |
)
|
252 |
nodes.append(situation_node)
|
253 |
node_ids[situation_node_id] = situation_node_id
|
254 |
|
255 |
+
# Edge from main node to situation node
|
256 |
+
edges.append(StreamlitFlowEdge(
|
257 |
+
id=f"edge_{main_node_id}_{situation_node_id}",
|
258 |
+
source=main_node_id,
|
259 |
+
target=situation_node_id,
|
260 |
+
animated=True
|
261 |
+
))
|
262 |
+
|
263 |
+
for idx, row in group.iterrows():
|
264 |
attempt = row['attempt']
|
265 |
action_emoji = row['action_emoji']
|
266 |
action_name = row['action_name']
|
|
|
273 |
markdown += f"{conclusion}\n"
|
274 |
|
275 |
# Create attempt node
|
276 |
+
attempt_node_id = f"attempt_{situation_id}_{attempt}_{idx}"
|
277 |
+
attempt_content = f"Attempt {attempt}: {action_emoji} {action_name}\n{outcome_str} {stars}\n{conclusion}"
|
|
|
|
|
|
|
278 |
|
279 |
attempt_node = StreamlitFlowNode(
|
280 |
attempt_node_id,
|
281 |
pos=(0, 0),
|
282 |
data={'content': attempt_content},
|
283 |
+
type='output',
|
284 |
+
target_position='top',
|
285 |
+
source_position='bottom',
|
286 |
+
width=250
|
287 |
)
|
288 |
nodes.append(attempt_node)
|
289 |
|
|
|
518 |
streamlit_flow('cat_rider_flow',
|
519 |
nodes,
|
520 |
edges,
|
521 |
+
layout=RadialLayout(),
|
522 |
fit_view=True,
|
523 |
+
height=1000)
|
524 |
except Exception as e:
|
525 |
st.error(f"An error occurred while rendering the journey graph: {str(e)}")
|
526 |
st.markdown("Please try refreshing the page if the graph doesn't appear.")
|