rajistics's picture
added default values
bac1592
raw
history blame
1.89 kB
import gradio as gr
import pypistats
from datetime import date
from dateutil.relativedelta import relativedelta
import pandas as pd
from fbprophet import Prophet
pd.options.plotting.backend = "plotly"
def get_data(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))]
return data
def get_plot2(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))]
#df = get_data(lib,time)
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
def get_plot(lib, time):
data = get_data(lib,time)
chart = data.plot(x="date", y="downloads")
return chart
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_plot2, [lib, time], plt)
time.change(get_plot2, [lib, time], plt)
demo.load(get_plot2, [lib, time], plt)
demo.launch()