RamAnanth1 commited on
Commit
c4f2558
·
1 Parent(s): ce85f3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -52
app.py CHANGED
@@ -11,56 +11,58 @@ import numpy as np
11
 
12
  from seir_model import *
13
 
14
- N = 10000 #Total Population
15
- initial_state = {
16
- "S": N-10,
17
- "E": 10,
18
- "I":0,
19
- "R":0
20
- }
21
- sys_params = {
22
- "infection_rate":[1],
23
- "recovery_rate":[1/14],
24
- "exposure_rate":[1/3]
25
- }
26
-
27
- partial_state_update_blocks = [
28
- {
29
- "policies":{
30
- "expsoed_growth":p_exposed,
31
- "infected_growth":p_infected,
32
- "recovered_growth":p_recovered,
33
-
34
- },
35
- "variables":{
36
- "S":s_susceptible,
37
- "E":s_exposed,
38
- "I":s_infected,
39
- "R":s_recovered,
40
- }
41
-
42
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
- ]
45
-
46
- del configs[:]
47
-
48
- timesteps = 100
49
- sim_config = config_sim({
50
- "N":1,
51
- "T":range(timesteps),
52
- "M":sys_params
53
- })
54
-
55
- experiment = Experiment()
56
- experiment.append_configs(
57
- sim_configs=sim_config,
58
- initial_state=initial_state,
59
- partial_state_update_blocks=partial_state_update_blocks
60
- )
61
-
62
- exec_context = ExecutionContext()
63
- simulation = Executor(exec_context=exec_context, configs=experiment.configs)
64
 
65
  css = """
66
  .gradio-container {
@@ -131,7 +133,8 @@ css = """
131
  }
132
  """
133
 
134
- def plot_seir(name):
 
135
  raw_result, tensor_fields, sessions = simulation.execute()
136
  result = pd.DataFrame(raw_result)
137
  pd.options.plotting.backend = "plotly"
@@ -148,9 +151,9 @@ with gr.Blocks(css = css) as demo:
148
  gr.Markdown("""
149
  ## Epidemic Simulation
150
  """)
151
- title_input = gr.Textbox(label = 'Enter title')
152
- simulate_btn = gr.Button('Simulation')
153
  graph = gr.Plot()
154
- simulate_btn.click(plot_seir, inputs = title_input, outputs = graph)
155
 
156
  demo.launch()
 
11
 
12
  from seir_model import *
13
 
14
+ def create_and_run_exp(population):
15
+ #Total Population : population
16
+ initial_state = {
17
+ "S": population-10,
18
+ "E": 10,
19
+ "I":0,
20
+ "R":0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  }
22
+ sys_params = {
23
+ "infection_rate":[1],
24
+ "recovery_rate":[1/14],
25
+ "exposure_rate":[1/3]
26
+ }
27
+
28
+ partial_state_update_blocks = [
29
+ {
30
+ "policies":{
31
+ "expsoed_growth":p_exposed,
32
+ "infected_growth":p_infected,
33
+ "recovered_growth":p_recovered,
34
+
35
+ },
36
+ "variables":{
37
+ "S":s_susceptible,
38
+ "E":s_exposed,
39
+ "I":s_infected,
40
+ "R":s_recovered,
41
+ }
42
+
43
+ }
44
+
45
+ ]
46
+
47
+ del configs[:]
48
+
49
+ timesteps = 100
50
+ sim_config = config_sim({
51
+ "N":1,
52
+ "T":range(timesteps),
53
+ "M":sys_params
54
+ })
55
+
56
+ experiment = Experiment()
57
+ experiment.append_configs(
58
+ sim_configs=sim_config,
59
+ initial_state=initial_state,
60
+ partial_state_update_blocks=partial_state_update_blocks
61
+ )
62
 
63
+ exec_context = ExecutionContext()
64
+ simulation = Executor(exec_context=exec_context, configs=experiment.configs)
65
+ return simulation
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
 
67
  css = """
68
  .gradio-container {
 
133
  }
134
  """
135
 
136
+ def plot_seir(population):
137
+ simulation = create_and_run_exp(population)
138
  raw_result, tensor_fields, sessions = simulation.execute()
139
  result = pd.DataFrame(raw_result)
140
  pd.options.plotting.backend = "plotly"
 
151
  gr.Markdown("""
152
  ## Epidemic Simulation
153
  """)
154
+ population_input = gr.Slider(1000, 100000, value=10000)
155
+ simulate_btn = gr.Button('Run Simulation')
156
  graph = gr.Plot()
157
+ simulate_btn.click(plot_seir, inputs = population_input, outputs = graph)
158
 
159
  demo.launch()