ddd
Browse files
app.py
CHANGED
|
@@ -1,74 +1,36 @@
|
|
| 1 |
-
import altair
|
| 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 |
-
|
| 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.
|
| 57 |
-
|
| 58 |
-
),
|
| 59 |
-
gr.Checkbox(label="Social Distancing?"),
|
| 60 |
]
|
| 61 |
-
outputs =
|
| 62 |
|
| 63 |
demo = gr.Interface(
|
| 64 |
fn=outbreak,
|
| 65 |
inputs=inputs,
|
| 66 |
outputs=outputs,
|
| 67 |
-
examples=[
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
],
|
| 72 |
cache_examples=True,
|
| 73 |
)
|
| 74 |
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import matplotlib
|
| 3 |
|
| 4 |
+
#matplotlib.use("Agg")
|
| 5 |
|
| 6 |
import matplotlib.pyplot as plt
|
| 7 |
+
# import numpy as np
|
| 8 |
+
# import plotly.express as px
|
| 9 |
+
# import pandas as pd
|
| 10 |
|
| 11 |
|
| 12 |
def outbreak(plot_type, r, month, countries, social_distancing):
|
| 13 |
+
return " 145 Fcfa/ for 2Kg"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
inputs = [
|
| 17 |
gr.Dropdown(["Matplotlib", "Plotly", "Altair"], label="Plot Type"),
|
|
|
|
| 18 |
gr.Dropdown(["January", "February", "March", "April", "May"], label="Month"),
|
| 19 |
+
gr.Dropdown(["January", "February", "March", "April", "May"], label="Month"),
|
| 20 |
+
gr.Dropdown(["January", "February", "March", "April", "May"], label="Month"),
|
| 21 |
+
gr.Dropdown(["January", "February", "March", "April", "May"], label="Month"),
|
|
|
|
| 22 |
]
|
| 23 |
+
outputs = "label"
|
| 24 |
|
| 25 |
demo = gr.Interface(
|
| 26 |
fn=outbreak,
|
| 27 |
inputs=inputs,
|
| 28 |
outputs=outputs,
|
| 29 |
+
# examples=[
|
| 30 |
+
# ["Matplotlib", 2, "March", ["Mexico", "UK"], True],
|
| 31 |
+
# ["Altair", 2, "March", ["Mexico", "Canada"], True],
|
| 32 |
+
# ["Plotly", 3.6, "February", ["Canada", "Mexico", "UK"], False],
|
| 33 |
+
# ],
|
| 34 |
cache_examples=True,
|
| 35 |
)
|
| 36 |
|