Jiranuwat commited on
Commit
5c4179a
·
1 Parent(s): 9c8f91b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -45
app.py CHANGED
@@ -76,7 +76,29 @@ def plotdata(t, s, i,r,R0, e=None):
76
  plt.tight_layout()
77
 
78
  return fig
79
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  #final model
81
  def SIR(country,R0,t_infective,pop):
82
  #R0 = 0.57 - 1.25
@@ -104,30 +126,8 @@ def SIR(country,R0,t_infective,pop):
104
  rmpe = mean_absolute_percentage_error(scaler,i[0:rangee])
105
 
106
 
107
- return R0,t_infective,beta,gamma,rmpe,plotdata(t, s, i,r,R0)
108
 
109
- def compare_plt(country,pop):
110
- fig = plt.figure(figsize=(12,6))
111
- ax = [fig.add_subplot(121, axisbelow=True),fig.add_subplot(122)]
112
- ax[0].set_title('Monkeypox confirmed cases')
113
- ax[0].plot(all_location[country]['total_cases'],lw=3,label='Infective')
114
- ax[0].set_xlabel('Days')
115
- ax[0].set_ylabel('Number of cases')
116
- ax[0].legend()
117
-
118
- scaler = all_location[country]['total_cases'].apply(lambda x : x/pop)
119
- ax[1].set_title('Monkeypox confirmed cases compare with model')
120
- ax[1].plot(scaler,lw=3,label='Real Infective')
121
- ax[1].plot(i,lw=3,label='SIR model Infective')
122
- ax[1].set_ylim(0,0.00005)
123
- ax[1].set_xlim(0,200)
124
- ax[1].set_xlabel('Days')
125
- ax[1].set_ylabel('Fraction Number of cases')
126
- ax[1].legend()
127
- plt.tight_layout()
128
-
129
- return fig
130
-
131
  def main():
132
  st.title("SIR Model for Monkeypox")
133
 
@@ -137,26 +137,7 @@ def main():
137
  R0 = st.slider("Basic Reproduction Number (R0)", 0.57, 3.00, 0.57)# user's input
138
  country_code = code[country][0]
139
  pop = pop_dict[country_code]
140
-
141
- fig = plt.figure(figsize=(12,6))
142
- ax = [fig.add_subplot(121, axisbelow=True),fig.add_subplot(122)]
143
- ax[0].set_title('Monkeypox confirmed cases')
144
- ax[0].plot(all_location[country_code]['total_cases'],lw=3,label='Infective')
145
- ax[0].set_xlabel('Days')
146
- ax[0].set_ylabel('Number of cases')
147
- ax[0].legend()
148
-
149
- scaler = all_location[country_code]['total_cases'].apply(lambda x : x/pop)
150
- ax[1].set_title('Monkeypox confirmed cases compare with model')
151
- ax[1].plot(scaler,lw=3,label='Real Infective')
152
- ax[1].plot(i,lw=3,label='SIR model Infective')
153
- ax[1].set_ylim(0,0.00005)
154
- ax[1].set_xlim(0,200)
155
- ax[1].set_xlabel('Days')
156
- ax[1].set_ylabel('Fraction Number of cases')
157
- ax[1].legend()
158
- plt.tight_layout()
159
-
160
  # clicked==True only when the button is clicked
161
  clicked = st.form_submit_button("Show Graph")
162
  if clicked:
@@ -164,8 +145,8 @@ def main():
164
  # Show SIR
165
  SIR_param = SIR(country_code,R0,recovery,pop)
166
 
 
167
  st.pyplot(SIR_param[-1])
168
- st.pyplot(fig)
169
  st.success("SIR model parameters for "+str(country)+" is")
170
  st.success("R0 = "+str(SIR_param[0]))
171
  st.success("Beta = "+str(SIR_param[2]))
 
76
  plt.tight_layout()
77
 
78
  return fig
79
+
80
+ def compare_plt(country,i,pop):
81
+ fig = plt.figure(figsize=(12,6))
82
+ ax = [fig.add_subplot(121, axisbelow=True),fig.add_subplot(122)]
83
+ ax[0].set_title('Monkeypox confirmed cases')
84
+ ax[0].plot(all_location[country]['total_cases'],lw=3,label='Infective')
85
+ ax[0].set_xlabel('Days')
86
+ ax[0].set_ylabel('Number of cases')
87
+ ax[0].legend()
88
+
89
+ scaler = all_location[country]['total_cases'].apply(lambda x : x/pop)
90
+ ax[1].set_title('Monkeypox confirmed cases compare with model')
91
+ ax[1].plot(scaler,lw=3,label='Real Infective')
92
+ ax[1].plot(i,lw=3,label='SIR model Infective')
93
+ ax[1].set_ylim(0,0.00005)
94
+ ax[1].set_xlim(0,200)
95
+ ax[1].set_xlabel('Days')
96
+ ax[1].set_ylabel('Fraction Number of cases')
97
+ ax[1].legend()
98
+ plt.tight_layout()
99
+
100
+ return fig
101
+
102
  #final model
103
  def SIR(country,R0,t_infective,pop):
104
  #R0 = 0.57 - 1.25
 
126
  rmpe = mean_absolute_percentage_error(scaler,i[0:rangee])
127
 
128
 
129
+ return R0,t_infective,beta,gamma,rmpe,plotdata(t, s, i,r,R0),compare_plt(country,i,pop)
130
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  def main():
132
  st.title("SIR Model for Monkeypox")
133
 
 
137
  R0 = st.slider("Basic Reproduction Number (R0)", 0.57, 3.00, 0.57)# user's input
138
  country_code = code[country][0]
139
  pop = pop_dict[country_code]
140
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  # clicked==True only when the button is clicked
142
  clicked = st.form_submit_button("Show Graph")
143
  if clicked:
 
145
  # Show SIR
146
  SIR_param = SIR(country_code,R0,recovery,pop)
147
 
148
+ st.pyplot(SIR_param[-2])
149
  st.pyplot(SIR_param[-1])
 
150
  st.success("SIR model parameters for "+str(country)+" is")
151
  st.success("R0 = "+str(SIR_param[0]))
152
  st.success("Beta = "+str(SIR_param[2]))