Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pypistats
|
| 3 |
+
from datetime import date
|
| 4 |
+
from dateutil.relativedelta import relativedelta
|
| 5 |
+
import pandas as pd
|
| 6 |
+
|
| 7 |
+
pd.options.plotting.backend = "plotly"
|
| 8 |
+
|
| 9 |
+
def get_plot(lib, time):
|
| 10 |
+
data = pypistats.overall(lib, total=True, format="pandas")
|
| 11 |
+
data = data.groupby("category").get_group("with_mirrors").sort_values("date")
|
| 12 |
+
start_date = date.today() - relativedelta(months=int(time.split(" ")[0]))
|
| 13 |
+
data = data[(data['date'] > str(start_date))]
|
| 14 |
+
chart = data.plot(x="date", y="downloads")
|
| 15 |
+
return chart
|
| 16 |
+
|
| 17 |
+
with gr.Blocks() as demo:
|
| 18 |
+
|
| 19 |
+
gr.Markdown(
|
| 20 |
+
"""
|
| 21 |
+
## Pypi Download Stats π
|
| 22 |
+
See live download stats for all of Hugging Face's open-source libraries π€
|
| 23 |
+
""")
|
| 24 |
+
with gr.Row():
|
| 25 |
+
lib = gr.Dropdown(["transformers", "datasets", "huggingface-hub", "gradio"], label="Library")
|
| 26 |
+
time = gr.Dropdown(["3 months", "6 months", "9 months", "12 months"], label="Downloads over the last...")
|
| 27 |
+
|
| 28 |
+
plt = gr.Plot()
|
| 29 |
+
|
| 30 |
+
lib.change(get_plot, [lib, time], plt)
|
| 31 |
+
time.change(get_plot, [lib, time], plt)
|
| 32 |
+
demo.load(get_plot, [lib, time], plt)
|
| 33 |
+
|
| 34 |
+
demo.launch()
|