awacke1 commited on
Commit
f28151c
Β·
1 Parent(s): e9a4754

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -93
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
- st.title('Community Hub Form')
34
-
35
- name = st.text_input('Name', key='name_input')
36
- email = st.text_input('Email', key='email_input')
37
- phone = st.text_input('Phone', key='phone_input')
38
-
39
- if st.button('Submit', key='submit_button'):
40
- save_data(name, email, phone)
41
- st.success('Form submitted!')
42
-
43
- if st.button('Reset', key='reset_button'):
44
- reset_data()
45
- st.success('Data reset!')
46
-
47
- if st.button('Show data', key='show_data_button'):
48
- show_data()
49
-
50
- st.write('Emails/SMS')
51
- with open('community.csv', mode='r') as csv_file:
52
- csv_reader = csv.DictReader(csv_file)
53
- for row in csv_reader:
54
- name = row['Name']
55
- email = row['Email']
56
- phone = row['Phone']
57
- st.write(f'{name}: {email} - {phone}')
58
- if st.button('Reply', key=f'reply_{name}'):
59
- st.text_input(f'Reply to {name}', key=f'reply_input_{name}')
60
- if st.button(f'Vote up {name}', key=f'vote_up_{name}'):
61
- st.success(f'{name} has been voted up!')
62
- if st.button(f'No thanks to {name}', key=f'vote_down_{name}'):
63
- st.warning(f'{name} has been voted down!')
64
- with open(f'{name}.txt', mode='w') as file:
65
- file.write(f'Life points: 0\n')
66
- st.write('')
67
-
68
- st.write('Add tip')
69
- tip = st.text_input('Tip', key='tip_input')
70
- if st.button('Submit tip', key='submit_tip_button'):
71
- emoji = random.choice(['πŸ‘', 'πŸ‘Œ', 'πŸ‘', 'πŸ’‘'])
72
- with open(f'{name}.txt', mode='a') as file:
73
- file.write(f'Tip' + ': {tip} {emoji}\nLife points: 10\n')
74
- st.success('Tip submitted!')
75
-
76
-
77
- import streamlit as st
78
- import pandas as pd
79
- import plotly.graph_objects as go
80
- import plotly.express as px
81
-
82
- # Define the states and conditions of interest
83
- states = ["Minnesota", "Florida", "California", "Washington", "Maine", "Texas"]
84
- top_n = 10
85
-
86
- # Define the list dictionary of top 10 health conditions descending by cost, with emojis
87
- health_conditions = [
88
- {"condition": "πŸ’” Heart disease", "emoji": "πŸ’—", "spending": 214.3},
89
- {"condition": "πŸ€• Trauma-related disorders", "emoji": "πŸš‘", "spending": 198.6},
90
- {"condition": "πŸ¦€ Cancer", "emoji": "πŸŽ—οΈ", "spending": 171.0},
91
- {"condition": "🧠 Mental disorders", "emoji": "🧘", "spending": 150.8},
92
- {"condition": "🦴 Osteoarthritis and joint disorders", "emoji": "πŸ₯", "spending": 142.4},
93
- {"condition": "πŸ’‰ Diabetes", "emoji": "🩸", "spending": 107.4},
94
- {"condition": "🫁 Chronic obstructive pulmonary disease and asthma", "emoji": "πŸ«€", "spending": 91.0},
95
- {"condition": "🩺 Hypertension", "emoji": "πŸ’‰", "spending": 83.9},
96
- {"condition": "πŸ”¬ Hyperlipidemia", "emoji": "πŸ”¬", "spending": 83.9},
97
- {"condition": "🦴 Back problems", "emoji": "🧍", "spending": 67.0}
98
- ]
99
-
100
- # Total the spending values
101
- total_spending = sum([hc["spending"] for hc in health_conditions])
102
-
103
- # Create a DataFrame from the list dictionary
104
- df_top_conditions = pd.DataFrame(health_conditions)
105
-
106
- # Create the map graph using Plotly Express
107
- locations = ["CA", "FL", "MN", "WA", "ME", "TX"]
108
- fig_map = px.choropleth(locations=locations, locationmode="USA-states", color=[1, 2, 3, 4, 5, 6], scope="usa")
109
- fig_map.update_layout(geo=dict(bgcolor= "rgba(0, 0, 0, 0)", lakecolor="rgb(255, 255, 255)"))
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