File size: 1,435 Bytes
b608947
 
 
 
 
ea198c5
b608947
 
 
 
ea198c5
181809c
 
 
 
 
 
b608947
 
 
 
 
 
 
 
 
 
 
 
 
 
4563e23
 
b608947
 
bac1592
 
b608947
 
 
ea198c5
 
 
b608947
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import gradio as gr
import pypistats
from datetime import date
from dateutil.relativedelta import relativedelta
import pandas as pd
from prophet import Prophet


pd.options.plotting.backend = "plotly"

def get_forecast(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]))
    df = data[(data['date'] > str(start_date))] 

    df1 = df[['date','downloads']]
    df1.columns = ['ds','y']

    m = Prophet()
    m.fit(df1)
    future = m.make_future_dataframe(periods=90)
    forecast = m.predict(future)
    fig1 = m.plot(forecast)
    return fig1 

with gr.Blocks() as demo:

    gr.Markdown(
    """
    ## Pypi Download Stats 📈 with Prophet Forecasting
    See live download stats for all of Hugging Face's open-source libraries 🤗 along with a 3 month forecast using Prophet
    """)
    with gr.Row():
        lib = gr.Dropdown(["transformers", "datasets", "huggingface-hub", "gradio"], value="transformers", label="Library")
        time = gr.Dropdown(["3 months", "6 months", "9 months", "12 months"], value="12 months", label="Downloads over the last...")

    plt = gr.Plot()

    lib.change(get_forecast, [lib, time], plt)
    time.change(get_forecast, [lib, time], plt)    
    demo.load(get_forecast, [lib, time], plt)    

demo.launch()