dd
Browse files
README.md
CHANGED
|
@@ -1,76 +1 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
import gradio as gr
|
| 4 |
-
from math import sqrt
|
| 5 |
-
import matplotlib
|
| 6 |
-
|
| 7 |
-
matplotlib.use("Agg")
|
| 8 |
-
|
| 9 |
-
import matplotlib.pyplot as plt
|
| 10 |
-
import numpy as np
|
| 11 |
-
import plotly.express as px
|
| 12 |
-
import pandas as pd
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
def outbreak(plot_type, r, month, countries, social_distancing):
|
| 16 |
-
months = ["January", "February", "March", "April", "May"]
|
| 17 |
-
m = months.index(month)
|
| 18 |
-
start_day = 30 * m
|
| 19 |
-
final_day = 30 * (m + 1)
|
| 20 |
-
x = np.arange(start_day, final_day + 1)
|
| 21 |
-
pop_count = {"USA": 350, "Canada": 40, "Mexico": 300, "UK": 120}
|
| 22 |
-
if social_distancing:
|
| 23 |
-
r = sqrt(r)
|
| 24 |
-
df = pd.DataFrame({"day": x})
|
| 25 |
-
for country in countries:
|
| 26 |
-
df[country] = x ** (r) * (pop_count[country] + 1)
|
| 27 |
-
|
| 28 |
-
if plot_type == "Matplotlib":
|
| 29 |
-
fig = plt.figure()
|
| 30 |
-
plt.plot(df["day"], df[countries].to_numpy())
|
| 31 |
-
plt.title("Outbreak in " + month)
|
| 32 |
-
plt.ylabel("Cases")
|
| 33 |
-
plt.xlabel("Days since Day 0")
|
| 34 |
-
plt.legend(countries)
|
| 35 |
-
return fig
|
| 36 |
-
elif plot_type == "Plotly":
|
| 37 |
-
fig = px.line(df, x="day", y=countries)
|
| 38 |
-
fig.update_layout(
|
| 39 |
-
title="Outbreak in " + month,
|
| 40 |
-
xaxis_title="Cases",
|
| 41 |
-
yaxis_title="Days Since Day 0",
|
| 42 |
-
)
|
| 43 |
-
return fig
|
| 44 |
-
elif plot_type == "Altair":
|
| 45 |
-
df = df.melt(id_vars="day").rename(columns={"variable": "country"})
|
| 46 |
-
fig = altair.Chart(df).mark_line().encode(x="day", y='value', color='country')
|
| 47 |
-
return fig
|
| 48 |
-
else:
|
| 49 |
-
raise ValueError("A plot type must be selected")
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
inputs = [
|
| 53 |
-
gr.Dropdown(["Matplotlib", "Plotly", "Altair"], label="Plot Type"),
|
| 54 |
-
gr.Slider(1, 4, 3.2, label="R"),
|
| 55 |
-
gr.Dropdown(["January", "February", "March", "April", "May"], label="Month"),
|
| 56 |
-
gr.CheckboxGroup(
|
| 57 |
-
["USA", "Canada", "Mexico", "UK"], label="Countries", value=["USA", "Canada"]
|
| 58 |
-
),
|
| 59 |
-
gr.Checkbox(label="Social Distancing?"),
|
| 60 |
-
]
|
| 61 |
-
outputs = gr.Plot()
|
| 62 |
-
|
| 63 |
-
demo = gr.Interface(
|
| 64 |
-
fn=outbreak,
|
| 65 |
-
inputs=inputs,
|
| 66 |
-
outputs=outputs,
|
| 67 |
-
examples=[
|
| 68 |
-
["Matplotlib", 2, "March", ["Mexico", "UK"], True],
|
| 69 |
-
["Altair", 2, "March", ["Mexico", "Canada"], True],
|
| 70 |
-
["Plotly", 3.6, "February", ["Canada", "Mexico", "UK"], False],
|
| 71 |
-
],
|
| 72 |
-
cache_examples=True,
|
| 73 |
-
)
|
| 74 |
-
|
| 75 |
-
if __name__ == "__main__":
|
| 76 |
-
demo.launch()
|
|
|
|
| 1 |
+
Machine model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|