merve HF Staff commited on
Commit
e7c1105
·
1 Parent(s): 584c8e7

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ def get_plot(lib, time):
8
+ data = pypistats.overall(lib, total=True, format="pandas")
9
+ data = data.groupby("category").get_group("with_mirrors").sort_values("date")
10
+ start_date = date.today() - relativedelta(months=int(time.split(" ")[0]))
11
+ data = data[(data['date'] > str(start_date))]
12
+ data.date = pd.to_datetime(pd.to_datetime(data.date))
13
+ return gr.LinePlot.update(value=data, x="date", y="downloads",
14
+ tooltip=['date', 'downloads'],
15
+ title=f"Pypi downloads of {lib} over last {time}",
16
+ overlay_point=True,
17
+ height=400,
18
+ width=900)
19
+
20
+
21
+ with gr.Blocks() as demo:
22
+ gr.Markdown(
23
+ """
24
+ ## Pypi Download Stats 📈
25
+ See live download stats for all of Hugging Face's open-source libraries 🤗
26
+ """)
27
+ with gr.Row():
28
+ lib = gr.Dropdown(["transformers", "datasets", "huggingface-hub", "gradio", "accelerate"],
29
+ value="gradio", label="Library")
30
+ time = gr.Dropdown(["3 months", "6 months", "9 months", "12 months"],
31
+ value="3 months", label="Downloads over the last...")
32
+
33
+ plt = gr.LinePlot()
34
+ # You can add multiple event triggers in 2 lines like this
35
+ for event in [lib.change, time.change, demo.load]:
36
+ event(get_plot, [lib, time], [plt])
37
+
38
+ if __name__ == "__main__":
39
+ demo.launch()