Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,53 +4,60 @@ import random
|
|
4 |
import plotly.graph_objects as go
|
5 |
import plotly.express as px
|
6 |
|
7 |
-
|
8 |
-
states
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
fig_sunburst.update_layout(title=f"Top {top_n} Health Conditions in {', '.join(states)} by Spending (Total: ${total_spending}B)")
|
49 |
-
|
50 |
-
# Display the sunburst chart and variants per condition in the Streamlit app
|
51 |
-
st.plotly_chart(fig_sunburst)
|
52 |
-
|
|
|
|
|
|
|
|
|
53 |
frequencies = roll()
|
54 |
fig_bar = px.bar(x=[f"Variant {i}" for i in range(1, 11)], y=frequencies[:10], labels={'x': 'Variant', 'y': 'Frequency'})
|
55 |
fig_bar.update_layout(title=f"Variants of {row['condition']} ({row['emoji']})")
|
56 |
st.plotly_chart(fig_bar)
|
|
|
|
|
|
|
|
4 |
import plotly.graph_objects as go
|
5 |
import plotly.express as px
|
6 |
|
7 |
+
def health_game():
|
8 |
+
# Define the states and conditions of interest
|
9 |
+
states = ["Minnesota", "Florida", "California"]
|
10 |
+
top_n = 10
|
11 |
+
|
12 |
+
# Define the list dictionary of top 10 health conditions descending by cost, with emojis, treatment recommendation and potential savings
|
13 |
+
health_conditions = [
|
14 |
+
{"condition": "π Heart disease", "emoji": "π", "spending": 214.3, "treatment": "Regular checkups with a cardiologist", "savings": "$1000"},
|
15 |
+
{"condition": "π€ Trauma-related disorders", "emoji": "π", "spending": 198.6, "treatment": "Counseling and physical therapy", "savings": "$500"},
|
16 |
+
{"condition": "π¦ Cancer", "emoji": "ποΈ", "spending": 171.0, "treatment": "Early detection and treatment", "savings": "$2000"},
|
17 |
+
{"condition": "π§ Mental disorders", "emoji": "π§", "spending": 150.8, "treatment": "Therapy and medication", "savings": "$1500"},
|
18 |
+
{"condition": "𦴠Osteoarthritis and joint disorders", "emoji": "π₯", "spending": 142.4, "treatment": "Low-impact exercise and physical therapy", "savings": "$800"},
|
19 |
+
{"condition": "π Diabetes", "emoji": "π©Έ", "spending": 107.4, "treatment": "Regular checkups and medication", "savings": "$1200"},
|
20 |
+
{"condition": "π« Chronic obstructive pulmonary disease and asthma", "emoji": "π«", "spending": 91.0, "treatment": "Inhalers and breathing exercises", "savings": "$600"},
|
21 |
+
{"condition": "π©Ί Hypertension", "emoji": "π", "spending": 83.9, "treatment": "Lifestyle changes and medication", "savings": "$900"},
|
22 |
+
{"condition": "π¬ Hyperlipidemia", "emoji": "π¬", "spending": 83.9, "treatment": "Lifestyle changes and medication", "savings": "$700"},
|
23 |
+
{"condition": "𦴠Back problems", "emoji": "π§", "spending": 67.0, "treatment": "Physical therapy and exercise", "savings": "$400"}
|
24 |
+
]
|
25 |
+
|
26 |
+
# Create a DataFrame from the list dictionary
|
27 |
+
df_top_conditions = pd.DataFrame(health_conditions)
|
28 |
+
|
29 |
+
# Calculate the total spending
|
30 |
+
total_spending = round(df_top_conditions["spending"].sum(), 1)
|
31 |
+
|
32 |
+
# Define the roll function
|
33 |
+
def roll():
|
34 |
+
rolls = [random.randint(1, 10) for _ in range(1000)]
|
35 |
+
frequencies = [rolls.count(i) for i in range(1, 11)]
|
36 |
+
return frequencies
|
37 |
+
|
38 |
+
# Define the sunburst chart
|
39 |
+
fig_sunburst = go.Figure(go.Sunburst(
|
40 |
+
labels=df_top_conditions["emoji"] + " " + df_top_conditions["condition"],
|
41 |
+
parents=[""] * top_n,
|
42 |
+
values=df_top_conditions["spending"],
|
43 |
+
maxdepth=2
|
44 |
+
))
|
45 |
+
|
46 |
+
# Customize the layout of the sunburst chart
|
47 |
+
|
48 |
+
fig_sunburst.update_layout(title=f"Top {top_n} Health Conditions in {', '.join(states)} by Spending (Total: ${total_spending}B)")
|
49 |
+
|
50 |
+
# Display the sunburst chart and variants per condition in the Streamlit app
|
51 |
+
st.plotly_chart(fig_sunburst)
|
52 |
+
condition_idx = st.selectbox("Select your current health condition", df_top_conditions.index)
|
53 |
+
row = df_top_conditions.loc[condition_idx]
|
54 |
+
|
55 |
+
st.write(f"Based on the severity of your {row['condition']}, we recommend {row['treatment']} for early treatment. This could save you up to {row['savings']} in healthcare costs.")
|
56 |
+
|
57 |
frequencies = roll()
|
58 |
fig_bar = px.bar(x=[f"Variant {i}" for i in range(1, 11)], y=frequencies[:10], labels={'x': 'Variant', 'y': 'Frequency'})
|
59 |
fig_bar.update_layout(title=f"Variants of {row['condition']} ({row['emoji']})")
|
60 |
st.plotly_chart(fig_bar)
|
61 |
+
|
62 |
+
|
63 |
+
health_game()
|