Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -2,8 +2,15 @@ import streamlit as st
|
|
2 |
import csv
|
3 |
import os
|
4 |
import random
|
|
|
|
|
|
|
5 |
|
6 |
def save_data(name, email, phone):
|
|
|
|
|
|
|
|
|
7 |
with open('community.csv', mode='a') as csv_file:
|
8 |
fieldnames = ['Name', 'Email', 'Phone']
|
9 |
writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
|
@@ -30,98 +37,83 @@ def show_data():
|
|
30 |
count = 0
|
31 |
|
32 |
def app():
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
# Create the bar chart using Plotly Graph Objects
|
112 |
-
fig_bar = go.Figure(go.Bar(x=df_top_conditions["emoji"] + " " + df_top_conditions["condition"], y=df_top_conditions["spending"], marker_color="#1f77b4"))
|
113 |
-
fig_bar.update_layout(title=f"Top {top_n} Health Conditions in {', '.join(states)} by Spending (Total: ${total_spending}B)",
|
114 |
-
yaxis_title="Spending ($B)", plot_bgcolor='rgba(0,0,0,0)', xaxis=dict(showgrid=False), yaxis=dict(showgrid=False))
|
115 |
-
|
116 |
-
# Display the map and the bar chart in Streamlit
|
117 |
-
col1, col2 = st.columns([2, 1])
|
118 |
-
with col1:
|
119 |
-
st.plotly_chart(fig_map, use_container_width=True)
|
120 |
-
with col2:
|
121 |
-
st.plotly_chart(fig_bar, use_container_width=True)
|
122 |
-
|
123 |
-
if __name__ == '__main__':
|
124 |
app()
|
125 |
|
126 |
-
|
127 |
-
|
|
|
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 save_data(name, email, phone):
|
10 |
+
if not os.path.exists('community.csv'):
|
11 |
+
with open('community.csv', mode='w') as csv_file:
|
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)
|
|
|
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 |
+
total_spending = sum([hc["spending"] for hc in health_conditions])
|
57 |
+
|
58 |
+
df_top_conditions = pd.DataFrame(health_conditions)
|
59 |
+
|
60 |
+
locations = ["CA", "FL", "MN", "WA", "ME", "TX"]
|
61 |
+
fig_map = px.choropleth(locations=locations, locationmode="USA-states", color=[1, 2, 3, 4, 5, 6], scope="usa")
|
62 |
+
fig_map.update_layout(geo=dict(bgcolor="rgba(0,0,0,0)", lakecolor="rgb(255, 255, 255)")
|
63 |
+
|
64 |
+
fig_bar = go.Figure(go.Bar(x=df_top_conditions["emoji"] + " " + df_top_conditions["condition"], y=df_top_conditions["spending"], marker_color="#1f77b4"))
|
65 |
+
fig_bar.update_layout(title=f"Top {top_n} Health Conditions in {', '.join(states)} by Spending (Total: ${total_spending}B)",
|
66 |
+
yaxis_title="Spending ($B)", plot_bgcolor='rgba(0,0,0,0)', xaxis=dict(showgrid=False), yaxis=dict(showgrid=False))
|
67 |
+
|
68 |
+
col1, col2 = st.columns([2, 1])
|
69 |
+
with col1:
|
70 |
+
st.plotly_chart(fig_map, use_container_width=True)
|
71 |
+
with col2:
|
72 |
+
st.plotly_chart(fig_bar, use_container_width=True)
|
73 |
+
|
74 |
+
st.title('Community Hub Form')
|
75 |
+
|
76 |
+
name = st.text_input('Name', key='name_input')
|
77 |
+
email = st.text_input('Email', key='email_input')
|
78 |
+
phone = st.text_input('Phone', key='phone_input')
|
79 |
+
|
80 |
+
if st.button('Submit', key='submit_button'):
|
81 |
+
save_data(name, email, phone)
|
82 |
+
st.success('Form submitted!')
|
83 |
+
|
84 |
+
if st.button('Reset', key='reset_button'):
|
85 |
+
reset_data()
|
86 |
+
st.success('Data reset!')
|
87 |
+
|
88 |
+
if st.button('Show data', key='show_data_button'):
|
89 |
+
show_data()
|
90 |
+
|
91 |
+
st.write('Emails/SMS')
|
92 |
+
with open('community.csv', mode='r') as csv_file:
|
93 |
+
csv_reader = csv.DictReader(csv_file)
|
94 |
+
for row in csv_reader:
|
95 |
+
name = row['Name']
|
96 |
+
email = row['Email']
|
97 |
+
phone = row['Phone']
|
98 |
+
st.write(f'{name}: {email} - {phone}')
|
99 |
+
if st.button('Reply', key=f'reply_{name}'):
|
100 |
+
st.text_input(f'Reply to {name}', key=f'reply_input_{name}')
|
101 |
+
if st.button(f'Vote up {name}', key=f'vote_up_{name}'):
|
102 |
+
st.success(f'{name} has been voted up!')
|
103 |
+
if st.button(f'No thanks to {name}', key=f'vote_down_{name}'):
|
104 |
+
st.warning(f'{name} has been voted down!')
|
105 |
+
with open(f'{name}.txt', mode='w') as file:
|
106 |
+
file.write(f'Life points: 0\n')
|
107 |
+
st.write('')
|
108 |
+
|
109 |
+
st.write('Add tip')
|
110 |
+
tip = st.text_input('Tip', key='tip_input')
|
111 |
+
if st.button('Submit tip', key='submit_tip_button'):
|
112 |
+
emoji = random.choice(['π', 'π', 'π', 'π‘'])
|
113 |
+
with open(f'{name}.txt', mode='a') as file:
|
114 |
+
file.write(f'Tip' + ': {tip} {emoji}\nLife points: 10\n')
|
115 |
+
st.success('Tip submitted!')
|
116 |
+
|
117 |
+
if name == 'main':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
app()
|
119 |
|
|
|
|