From 252f1640262e5486fcc03cda9e18b5d025b507e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20=C3=96zdemir?= Date: Fri, 10 Jun 2022 09:20:58 +0300 Subject: [PATCH] add-multiple-event-demo (#1519) --- demo/blocks_multiple_event_triggers/run.py | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 demo/blocks_multiple_event_triggers/run.py diff --git a/demo/blocks_multiple_event_triggers/run.py b/demo/blocks_multiple_event_triggers/run.py new file mode 100644 index 0000000000..781f391bde --- /dev/null +++ b/demo/blocks_multiple_event_triggers/run.py @@ -0,0 +1,34 @@ +import gradio as gr +import pypistats +from datetime import date +from dateutil.relativedelta import relativedelta +import pandas as pd + +pd.options.plotting.backend = "plotly" + + +def get_plot(lib, time): + data = pypistats.overall(lib, total=True, format="pandas") + data = data.groupby("category").get_group("with_mirrors").sort_values("date") + start_date = date.today() - relativedelta(months=int(time.split(" ")[0])) + data = data[(data['date'] > str(start_date))] + chart = data.plot(x="date", y="downloads") + return chart + + +with gr.Blocks() as demo: + gr.Markdown( + """ + ## Pypi Download Stats 📈 + See live download stats for all of Hugging Face's open-source libraries 🤗 + """) + with gr.Row(): + lib = gr.Dropdown(["transformers", "datasets", "huggingface-hub", "gradio", "accelerate"], label="Library") + time = gr.Dropdown(["3 months", "6 months", "9 months", "12 months"], label="Downloads over the last...") + + plt = gr.Plot() + # You can add multiple event triggers in 2 lines like this + for event in [lib.change, time.change, demo.load]: + event(get_plot, [lib, time], [plt]) + +demo.launch()