Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,125 +1,63 @@
|
|
1 |
import streamlit as st
|
2 |
-
import csv
|
3 |
-
import os
|
4 |
-
import random
|
5 |
import pandas as pd
|
|
|
6 |
import plotly.graph_objects as go
|
7 |
import plotly.express as px
|
8 |
|
9 |
-
def
|
10 |
-
|
11 |
-
|
12 |
-
writer = csv.writer(csv_file)
|
13 |
-
writer.writerow(['Name', 'Email', 'Phone'])
|
14 |
-
with open('community.csv', mode='a') as csv_file:
|
15 |
-
fieldnames = ['Name', 'Email', 'Phone']
|
16 |
-
writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
|
17 |
-
if os.stat('community.csv').st_size == 0:
|
18 |
-
writer.writeheader()
|
19 |
-
writer.writerow({'Name': name, 'Email': email, 'Phone': phone})
|
20 |
-
with open(f'{name}.txt', mode='w') as file:
|
21 |
-
file.write(f'Name: {name}\nEmail: {email}\nPhone: {phone}\n')
|
22 |
-
|
23 |
-
def reset_data():
|
24 |
-
os.remove('community.csv')
|
25 |
-
for file in os.listdir():
|
26 |
-
if file.endswith('.txt'):
|
27 |
-
os.remove(file)
|
28 |
-
|
29 |
-
def show_data():
|
30 |
-
count = 0
|
31 |
-
with open('community.csv', mode='r') as csv_file:
|
32 |
-
csv_reader = csv.DictReader(csv_file)
|
33 |
-
for row in csv_reader:
|
34 |
-
count += 1
|
35 |
-
if count == 3:
|
36 |
-
st.write(f'{row["Name"]}: {row["Email"]} - {row["Phone"]}')
|
37 |
-
count = 0
|
38 |
-
|
39 |
-
def app():
|
40 |
-
states = ["Minnesota", "Florida", "California", "Washington", "Maine", "Texas"]
|
41 |
top_n = 10
|
42 |
|
|
|
43 |
health_conditions = [
|
44 |
-
{"condition": "π Heart disease", "emoji": "π", "spending": 214.3},
|
45 |
-
{"condition": "π€ Trauma-related disorders", "emoji": "π", "spending": 198.6},
|
46 |
-
{"condition": "π¦ Cancer", "emoji": "ποΈ", "spending": 171.0},
|
47 |
-
{"condition": "π§ Mental disorders", "emoji": "π§", "spending": 150.8},
|
48 |
-
{"condition": "𦴠Osteoarthritis and joint disorders", "emoji": "π₯", "spending": 142.4},
|
49 |
-
{"condition": "π Diabetes", "emoji": "π©Έ", "spending": 107.4},
|
50 |
-
{"condition": "π« Chronic obstructive pulmonary disease and asthma", "emoji": "π«", "spending": 91.0},
|
51 |
-
{"condition": "π©Ί Hypertension", "emoji": "π", "spending": 83.9},
|
52 |
-
{"condition": "π¬ Hyperlipidemia", "emoji": "π¬", "spending": 83.9},
|
53 |
-
{"condition": "𦴠Back problems", "emoji": "π§", "spending": 67.0}
|
54 |
]
|
55 |
|
56 |
-
|
57 |
-
|
58 |
df_top_conditions = pd.DataFrame(health_conditions)
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
#fig_map.update_layout(geo=dict(bgcolor="rgba(0,0,0,0)", lakecolor="rgb(255, 255, 255)")
|
63 |
-
|
64 |
-
fig_map.update_layout(geo=dict(bgcolor= "rgba(0, 0, 0, 0)", lakecolor="rgb(255, 255, 255)"))
|
65 |
-
|
66 |
-
fig_bar = go.Figure(go.Bar(x=df_top_conditions["emoji"] + " " + df_top_conditions["condition"], y=df_top_conditions["spending"], marker_color="#1f77b4"))
|
67 |
-
fig_bar.update_layout(title=f"Top {top_n} Health Conditions in {', '.join(states)} by Spending (Total: ${total_spending}B)",
|
68 |
-
yaxis_title="Spending ($B)", plot_bgcolor='rgba(0,0,0,0)', xaxis=dict(showgrid=False), yaxis=dict(showgrid=False))
|
69 |
-
|
70 |
-
|
71 |
-
# fig_bar.update_layout(title=f"Top {top_n} Health Conditions in {', '.join(states)} by Spending (Total: ${total_spending}B)",
|
72 |
-
# yaxis_title="Spending ($B)", plot_bgcolor='rgba(0,0,0,0)', xaxis=dict(showgrid=False), yaxis=dict(showgrid=False))
|
73 |
-
|
74 |
-
col1, col2 = st.columns([2, 1])
|
75 |
-
with col1:
|
76 |
-
st.plotly_chart(fig_map, use_container_width=True)
|
77 |
-
with col2:
|
78 |
-
st.plotly_chart(fig_bar, use_container_width=True)
|
79 |
-
|
80 |
-
st.title('Community Hub Form')
|
81 |
|
82 |
-
|
83 |
-
|
84 |
-
|
|
|
|
|
85 |
|
86 |
-
|
87 |
-
|
88 |
-
|
|
|
|
|
|
|
|
|
89 |
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
|
94 |
-
|
95 |
-
|
|
|
|
|
96 |
|
97 |
-
st.write('
|
98 |
-
with open('community.csv', mode='r') as csv_file:
|
99 |
-
csv_reader = csv.DictReader(csv_file)
|
100 |
-
for row in csv_reader:
|
101 |
-
name = row['Name']
|
102 |
-
email = row['Email']
|
103 |
-
phone = row['Phone']
|
104 |
-
st.write(f'{name}: {email} - {phone}')
|
105 |
-
if st.button('Reply', key=f'reply_{name}'):
|
106 |
-
st.text_input(f'Reply to {name}', key=f'reply_input_{name}')
|
107 |
-
if st.button(f'Vote up {name}', key=f'vote_up_{name}'):
|
108 |
-
st.success(f'{name} has been voted up!')
|
109 |
-
if st.button(f'No thanks to {name}', key=f'vote_down_{name}'):
|
110 |
-
st.warning(f'{name} has been voted down!')
|
111 |
-
with open(f'{name}.txt', mode='w') as file:
|
112 |
-
file.write(f'Life points: 0\n')
|
113 |
-
st.write('')
|
114 |
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
with open(f'{name}.txt', mode='a') as file:
|
120 |
-
file.write(f'Tip' + ': {tip} {emoji}\nLife points: 10\n')
|
121 |
-
st.success('Tip submitted!')
|
122 |
|
123 |
-
if name == 'main':
|
124 |
-
app()
|
125 |
|
|
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
2 |
import pandas as pd
|
3 |
+
import random
|
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()
|