gradio/demo/timeseries-forecasting-with-prophet/run.py
Ali Abdalla 597337dcb8
Adding a Playground Tab to the Website (#1860)
* added playground with 12 demos

* change name to recipes, restyle navbar

* add explanatory text to page

* fix demo mapping

* categorize demos, clean up design

* styling

* cateogry naming and emojis

* refactor and add text demos

* add view code button

* remove opening slash in embed

* styling

* add image demos

* adding plot demos

* remove see code button

* removed submodules

* changes

* add audio models

* remove fun section

* remove tests in image semgentation demo repo

* requested changes

* add outbreak_forecast

* fix broken demos

* remove images and models, add new demos

* remove readmes, change to run.py, add description as comment

* move to /demos folder, clean up dict

* add upload_to_spaces script

* fix script, clean repos, and add to docker file

* fix python versioning issue

* env variable

* fix

* env fixes

* spaces instead of tabs

* revert to original networking.py

* fix rate limiting in asr and autocomplete

* change name to demos

* clean up navbar

* move url and description, remove code comments

* add tabs to demos

* remove margins and footer from embedded demo

* font consistency

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
2022-09-15 08:24:10 -07:00

41 lines
1.5 KiB
Python

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 popular open-source libraries 🤗 along with a 3 month forecast using Prophet. The [ source code for this Gradio demo is here](https://huggingface.co/spaces/gradio/timeseries-forecasting-with-prophet/blob/main/app.py).
""")
with gr.Row():
lib = gr.Dropdown(["pandas", "scikit-learn", "torch", "prophet"], label="Library", value="pandas")
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()