Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
README.md
CHANGED
|
@@ -5,7 +5,7 @@ emoji: 🔥
|
|
| 5 |
colorFrom: indigo
|
| 6 |
colorTo: indigo
|
| 7 |
sdk: gradio
|
| 8 |
-
sdk_version:
|
| 9 |
app_file: run.py
|
| 10 |
pinned: false
|
| 11 |
hf_oauth: true
|
|
|
|
| 5 |
colorFrom: indigo
|
| 6 |
colorTo: indigo
|
| 7 |
sdk: gradio
|
| 8 |
+
sdk_version: 5.0.0
|
| 9 |
app_file: run.py
|
| 10 |
pinned: false
|
| 11 |
hf_oauth: true
|
requirements.txt
CHANGED
|
@@ -2,4 +2,4 @@ numpy
|
|
| 2 |
matplotlib
|
| 3 |
bokeh
|
| 4 |
plotly
|
| 5 |
-
altair
|
|
|
|
| 2 |
matplotlib
|
| 3 |
bokeh
|
| 4 |
plotly
|
| 5 |
+
altair
|
run.ipynb
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: outbreak_forecast\n", "### Generate a plot based on 5 inputs.\n", " "]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio numpy matplotlib bokeh plotly altair"]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import
|
|
|
|
| 1 |
+
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: outbreak_forecast\n", "### Generate a plot based on 5 inputs.\n", " "]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio numpy matplotlib bokeh plotly altair "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "from math import sqrt\n", "import numpy as np\n", "import pandas as pd\n", "\n", "def outbreak(plot_type, r, month, countries, social_distancing):\n", " months = [\"January\", \"February\", \"March\", \"April\", \"May\"]\n", " m = months.index(month)\n", " start_day = 30 * m\n", " final_day = 30 * (m + 1)\n", " x = np.arange(start_day, final_day + 1)\n", " pop_count = {\"USA\": 350, \"Canada\": 40, \"Mexico\": 300, \"UK\": 120}\n", " if social_distancing:\n", " r = sqrt(r)\n", " df = pd.DataFrame({\"day\": x})\n", " for country in countries:\n", " df[country] = x ** (r) * (pop_count[country] + 1)\n", "\n", " if plot_type == \"Matplotlib\":\n", " import matplotlib.pyplot as plt\n", "\n", " fig = plt.figure()\n", " plt.plot(df[\"day\"], df[countries].to_numpy())\n", " plt.title(\"Outbreak in \" + month)\n", " plt.ylabel(\"Cases\")\n", " plt.xlabel(\"Days since Day 0\")\n", " plt.legend(countries)\n", " return fig\n", " elif plot_type == \"Plotly\":\n", " import plotly.express as px\n", "\n", " fig = px.line(df, x=\"day\", y=countries)\n", " fig.update_layout(\n", " title=\"Outbreak in \" + month,\n", " xaxis_title=\"Cases\",\n", " yaxis_title=\"Days Since Day 0\",\n", " )\n", " return fig\n", " elif plot_type == \"Altair\":\n", " import altair\n", "\n", " df = df.melt(id_vars=\"day\").rename(columns={\"variable\": \"country\"})\n", " fig = altair.Chart(df).mark_line().encode(x=\"day\", y=\"value\", color=\"country\")\n", " return fig\n", " elif plot_type == \"Bokeh\":\n", " from bokeh.plotting import figure\n", " from bokeh.models import ColumnDataSource\n", "\n", " source = ColumnDataSource(df)\n", " fig = figure(title=\"Outbreak in \" + month, x_axis_label=\"Days since Day 0\", y_axis_label=\"Cases\")\n", " for country in countries:\n", " fig.line(\"day\", country, source=source, legend_label=country)\n", " return fig\n", " else:\n", " raise ValueError(\"A plot type must be selected\")\n", "\n", "inputs = [\n", " gr.Dropdown([\"Matplotlib\", \"Plotly\", \"Altair\", \"Bokeh\"], label=\"Plot Type\", value=\"Matplotlib\"),\n", " gr.Slider(1, 4, 3.2, label=\"R\"),\n", " gr.Dropdown([\"January\", \"February\", \"March\", \"April\", \"May\"], label=\"Month\", value=\"March\"),\n", " gr.CheckboxGroup(\n", " [\"USA\", \"Canada\", \"Mexico\", \"UK\"], label=\"Countries\", value=[\"USA\", \"Canada\"]\n", " ),\n", " gr.Checkbox(label=\"Social Distancing?\"),\n", "]\n", "outputs = gr.Plot()\n", "\n", "demo = gr.Interface(\n", " fn=outbreak,\n", " inputs=inputs,\n", " outputs=outputs,\n", " examples=[\n", " [\"Matplotlib\", 2, \"March\", [\"Mexico\", \"UK\"], True],\n", " [\"Altair\", 2, \"March\", [\"Mexico\", \"Canada\"], True],\n", " [\"Plotly\", 3.6, \"February\", [\"Canada\", \"Mexico\", \"UK\"], False],\n", " [\"Bokeh\", 3.2, \"April\", [\"Canada\", \"UK\"], False],\n", " ],\n", " cache_examples=True,\n", ")\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
run.py
CHANGED
|
@@ -1,10 +1,6 @@
|
|
| 1 |
-
import altair
|
| 2 |
-
|
| 3 |
import gradio as gr
|
| 4 |
from math import sqrt
|
| 5 |
-
import matplotlib.pyplot as plt
|
| 6 |
import numpy as np
|
| 7 |
-
import plotly.express as px
|
| 8 |
import pandas as pd
|
| 9 |
|
| 10 |
def outbreak(plot_type, r, month, countries, social_distancing):
|
|
@@ -21,6 +17,8 @@ def outbreak(plot_type, r, month, countries, social_distancing):
|
|
| 21 |
df[country] = x ** (r) * (pop_count[country] + 1)
|
| 22 |
|
| 23 |
if plot_type == "Matplotlib":
|
|
|
|
|
|
|
| 24 |
fig = plt.figure()
|
| 25 |
plt.plot(df["day"], df[countries].to_numpy())
|
| 26 |
plt.title("Outbreak in " + month)
|
|
@@ -29,6 +27,8 @@ def outbreak(plot_type, r, month, countries, social_distancing):
|
|
| 29 |
plt.legend(countries)
|
| 30 |
return fig
|
| 31 |
elif plot_type == "Plotly":
|
|
|
|
|
|
|
| 32 |
fig = px.line(df, x="day", y=countries)
|
| 33 |
fig.update_layout(
|
| 34 |
title="Outbreak in " + month,
|
|
@@ -37,16 +37,27 @@ def outbreak(plot_type, r, month, countries, social_distancing):
|
|
| 37 |
)
|
| 38 |
return fig
|
| 39 |
elif plot_type == "Altair":
|
|
|
|
|
|
|
| 40 |
df = df.melt(id_vars="day").rename(columns={"variable": "country"})
|
| 41 |
fig = altair.Chart(df).mark_line().encode(x="day", y="value", color="country")
|
| 42 |
return fig
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
else:
|
| 44 |
raise ValueError("A plot type must be selected")
|
| 45 |
|
| 46 |
inputs = [
|
| 47 |
-
gr.Dropdown(["Matplotlib", "Plotly", "Altair"], label="Plot Type"),
|
| 48 |
gr.Slider(1, 4, 3.2, label="R"),
|
| 49 |
-
gr.Dropdown(["January", "February", "March", "April", "May"], label="Month"),
|
| 50 |
gr.CheckboxGroup(
|
| 51 |
["USA", "Canada", "Mexico", "UK"], label="Countries", value=["USA", "Canada"]
|
| 52 |
),
|
|
@@ -62,6 +73,7 @@ demo = gr.Interface(
|
|
| 62 |
["Matplotlib", 2, "March", ["Mexico", "UK"], True],
|
| 63 |
["Altair", 2, "March", ["Mexico", "Canada"], True],
|
| 64 |
["Plotly", 3.6, "February", ["Canada", "Mexico", "UK"], False],
|
|
|
|
| 65 |
],
|
| 66 |
cache_examples=True,
|
| 67 |
)
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from math import sqrt
|
|
|
|
| 3 |
import numpy as np
|
|
|
|
| 4 |
import pandas as pd
|
| 5 |
|
| 6 |
def outbreak(plot_type, r, month, countries, social_distancing):
|
|
|
|
| 17 |
df[country] = x ** (r) * (pop_count[country] + 1)
|
| 18 |
|
| 19 |
if plot_type == "Matplotlib":
|
| 20 |
+
import matplotlib.pyplot as plt
|
| 21 |
+
|
| 22 |
fig = plt.figure()
|
| 23 |
plt.plot(df["day"], df[countries].to_numpy())
|
| 24 |
plt.title("Outbreak in " + month)
|
|
|
|
| 27 |
plt.legend(countries)
|
| 28 |
return fig
|
| 29 |
elif plot_type == "Plotly":
|
| 30 |
+
import plotly.express as px
|
| 31 |
+
|
| 32 |
fig = px.line(df, x="day", y=countries)
|
| 33 |
fig.update_layout(
|
| 34 |
title="Outbreak in " + month,
|
|
|
|
| 37 |
)
|
| 38 |
return fig
|
| 39 |
elif plot_type == "Altair":
|
| 40 |
+
import altair
|
| 41 |
+
|
| 42 |
df = df.melt(id_vars="day").rename(columns={"variable": "country"})
|
| 43 |
fig = altair.Chart(df).mark_line().encode(x="day", y="value", color="country")
|
| 44 |
return fig
|
| 45 |
+
elif plot_type == "Bokeh":
|
| 46 |
+
from bokeh.plotting import figure
|
| 47 |
+
from bokeh.models import ColumnDataSource
|
| 48 |
+
|
| 49 |
+
source = ColumnDataSource(df)
|
| 50 |
+
fig = figure(title="Outbreak in " + month, x_axis_label="Days since Day 0", y_axis_label="Cases")
|
| 51 |
+
for country in countries:
|
| 52 |
+
fig.line("day", country, source=source, legend_label=country)
|
| 53 |
+
return fig
|
| 54 |
else:
|
| 55 |
raise ValueError("A plot type must be selected")
|
| 56 |
|
| 57 |
inputs = [
|
| 58 |
+
gr.Dropdown(["Matplotlib", "Plotly", "Altair", "Bokeh"], label="Plot Type", value="Matplotlib"),
|
| 59 |
gr.Slider(1, 4, 3.2, label="R"),
|
| 60 |
+
gr.Dropdown(["January", "February", "March", "April", "May"], label="Month", value="March"),
|
| 61 |
gr.CheckboxGroup(
|
| 62 |
["USA", "Canada", "Mexico", "UK"], label="Countries", value=["USA", "Canada"]
|
| 63 |
),
|
|
|
|
| 73 |
["Matplotlib", 2, "March", ["Mexico", "UK"], True],
|
| 74 |
["Altair", 2, "March", ["Mexico", "Canada"], True],
|
| 75 |
["Plotly", 3.6, "February", ["Canada", "Mexico", "UK"], False],
|
| 76 |
+
["Bokeh", 3.2, "April", ["Canada", "UK"], False],
|
| 77 |
],
|
| 78 |
cache_examples=True,
|
| 79 |
)
|