Spaces:
Sleeping
Sleeping
import gradio as gr | |
from cadCAD.configuration.utils import config_sim | |
from cadCAD.configuration import Experiment | |
from cadCAD.engine import ExecutionMode, ExecutionContext | |
from cadCAD.engine import Executor | |
from cadCAD import configs | |
import pandas as pd | |
import numpy as np | |
from seir_model import * | |
N = 10000 #Total Population | |
initial_state = { | |
"S": N-10, | |
"E": 10, | |
"I":0, | |
"R":0 | |
} | |
sys_params = { | |
"infection_rate":[1], | |
"recovery_rate":[1/14], | |
"exposure_rate":[1/3] | |
} | |
partial_state_update_blocks = [ | |
{ | |
"policies":{ | |
"expsoed_growth":p_exposed, | |
"infected_growth":p_infected, | |
"recovered_growth":p_recovered, | |
}, | |
"variables":{ | |
"S":s_susceptible, | |
"E":s_exposed, | |
"I":s_infected, | |
"R":s_recovered, | |
} | |
} | |
] | |
del configs[:] | |
timesteps = 100 | |
sim_config = config_sim({ | |
"N":1, | |
"T":range(timesteps), | |
"M":sys_params | |
}) | |
experiment = Experiment() | |
experiment.append_configs( | |
sim_configs=sim_config, | |
initial_state=initial_state, | |
partial_state_update_blocks=partial_state_update_blocks | |
) | |
exec_context = ExecutionContext() | |
simulation = Executor(exec_context=exec_context, configs=experiment.configs) | |
def plot_seir(name): | |
raw_result, tensor_fields, sessions = simulation.execute() | |
result = pd.DataFrame(raw_result) | |
pd.options.plotting.backend = "plotly" | |
fig = result.plot( | |
kind = "line", | |
x = "timestep", | |
y= ["S","E","I", "R"]) | |
fig.update_layout(title = name, | |
xaxis_title="Time (Days)", | |
yaxis_title="People") | |
return fig | |
graph = gr.Plot() | |
iface = gr.Interface(fn=plot_seir, inputs="text", outputs=graph) | |
iface.launch() |