Spaces:
Sleeping
Sleeping
File size: 1,866 Bytes
1b3abf3 88db5bb 1b3abf3 |
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 46 47 48 49 50 51 52 53 54 55 56 57 58 |
import gradio as gr
import pypistats
from datetime import date
from dateutil.relativedelta import relativedelta
from darts import TimeSeries
from darts.models import ExponentialSmoothing
from matplotlib import pyplot
import pandas as pd
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["date"] = pd.to_datetime(df1["date"])
df1 = df1.set_index(["date"])
target = TimeSeries.from_dataframe(df1, freq="D")
model = ExponentialSmoothing()
model.fit(target)
prediction = model.predict(90, num_samples=500)
fig, axes = pyplot.subplots(figsize=(20, 12))
target.plot()
prediction.plot()
pyplot.legend()
return fig
with gr.Blocks() as demo:
gr.Markdown(
"""
**Pypi Download Stats π with Darts Forecasting**: see live download stats for popular open-source libraries π€ along with a 3 month forecast using Darts. The [ source code for this Gradio demo is here](https://huggingface.co/spaces/ivelin/darts-demo/tree/main).
"""
)
with gr.Row():
lib = gr.Dropdown(
["pandas", "scikit-learn", "torch", "prophet", "darts"],
label="Library",
value="darts",
)
time = gr.Dropdown(
["3 months", "6 months", "9 months", "12 months"],
label="Downloads over the last...",
value="12 months",
)
plt = gr.Plot()
lib.change(get_forecast, [lib, time], plt, queue=False)
time.change(get_forecast, [lib, time], plt, queue=False)
demo.load(get_forecast, [lib, time], plt, queue=False)
demo.launch() |