rajistics commited on
Commit
b608947
·
1 Parent(s): a500255

first upload

Browse files
Files changed (2) hide show
  1. app.py +52 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ from fbprophet import Prophet
7
+
8
+
9
+ pd.options.plotting.backend = "plotly"
10
+
11
+ def get_data(lib,time):
12
+ data = pypistats.overall(lib, total=True, format="pandas")
13
+ data = data.groupby("category").get_group("with_mirrors").sort_values("date")
14
+ start_date = date.today() - relativedelta(months=int(time.split(" ")[0]))
15
+ data = data[(data['date'] > str(start_date))]
16
+ return data
17
+
18
+ def get_plot2(lib, time):
19
+ df = get_data(lib,time)
20
+ df1 = df[['date','downloads']]
21
+ df1.columns = ['ds','y']
22
+
23
+ m = Prophet()
24
+ m.fit(df1)
25
+ future = m.make_future_dataframe(periods=90)
26
+ forecast = m.predict(future)
27
+ fig1 = m.plot(forecast)
28
+ return fig1
29
+
30
+ def get_plot(lib, time):
31
+ data = get_data(lib,time)
32
+ chart = data.plot(x="date", y="downloads")
33
+ return chart
34
+
35
+ with gr.Blocks() as demo:
36
+
37
+ gr.Markdown(
38
+ """
39
+ ## Pypi Download Stats 📈
40
+ See live download stats for all of Hugging Face's open-source libraries 🤗
41
+ """)
42
+ with gr.Row():
43
+ lib = gr.Dropdown(["transformers", "datasets", "huggingface-hub", "gradio"], label="Library")
44
+ time = gr.Dropdown(["3 months", "6 months", "9 months", "12 months"], label="Downloads over the last...")
45
+
46
+ plt = gr.Plot()
47
+
48
+ lib.change(get_plot2, [lib, time], plt)
49
+ time.change(get_plot2, [lib, time], plt)
50
+ demo.load(get_plot2, [lib, time], plt)
51
+
52
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ pypistats
2
+ plotly
3
+ pystan==2.19.1.1
4
+ prophet