2022-01-21 21:44:12 +08:00
|
|
|
from math import sqrt
|
|
|
|
|
2021-05-24 23:31:44 +08:00
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
import numpy as np
|
2022-01-21 21:44:12 +08:00
|
|
|
|
|
|
|
import gradio as gr
|
|
|
|
|
2021-05-24 23:31:44 +08:00
|
|
|
|
|
|
|
def outbreak(r, month, countries, social_distancing):
|
|
|
|
months = ["January", "February", "March", "April", "May"]
|
|
|
|
m = months.index(month)
|
|
|
|
start_day = 30 * m
|
|
|
|
final_day = 30 * (m + 1)
|
2022-01-21 21:44:12 +08:00
|
|
|
x = np.arange(start_day, final_day + 1)
|
2021-05-24 23:31:44 +08:00
|
|
|
day_count = x.shape[0]
|
|
|
|
pop_count = {"USA": 350, "Canada": 40, "Mexico": 300, "UK": 120}
|
|
|
|
r = sqrt(r)
|
|
|
|
if social_distancing:
|
|
|
|
r = sqrt(r)
|
|
|
|
for i, country in enumerate(countries):
|
|
|
|
series = x ** (r) * (i + 1)
|
|
|
|
plt.plot(x, series)
|
|
|
|
plt.title("Outbreak in " + month)
|
|
|
|
plt.ylabel("Cases")
|
|
|
|
plt.xlabel("Days since Day 0")
|
|
|
|
plt.legend(countries)
|
|
|
|
return plt
|
|
|
|
|
2022-01-21 21:44:12 +08:00
|
|
|
|
2022-03-29 06:13:39 +08:00
|
|
|
demo = gr.Interface(
|
2022-01-21 21:44:12 +08:00
|
|
|
outbreak,
|
2021-05-24 23:31:44 +08:00
|
|
|
[
|
2022-03-29 06:13:39 +08:00
|
|
|
gr.Slider(minimum=1, maximum=4, default_value=3.2, label="R"),
|
2022-04-05 06:47:51 +08:00
|
|
|
gr.Dropdown(["January", "February", "March", "April", "May"], label="Month"),
|
2022-03-29 06:13:39 +08:00
|
|
|
gr.CheckboxGroup(["USA", "Canada", "Mexico", "UK"], label="Countries"),
|
|
|
|
gr.Checkbox(label="Social Distancing?"),
|
2022-01-21 21:44:12 +08:00
|
|
|
],
|
|
|
|
"plot",
|
|
|
|
)
|
2021-05-24 23:31:44 +08:00
|
|
|
if __name__ == "__main__":
|
2022-03-29 06:13:39 +08:00
|
|
|
demo.launch()
|