Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Upload with huggingface_hub
Browse files
README.md
CHANGED
@@ -6,7 +6,6 @@ colorFrom: indigo
|
|
6 |
colorTo: indigo
|
7 |
sdk: gradio
|
8 |
sdk_version: 3.4.1
|
9 |
-
|
10 |
-
app_file: app.py
|
11 |
pinned: false
|
12 |
---
|
|
|
6 |
colorTo: indigo
|
7 |
sdk: gradio
|
8 |
sdk_version: 3.4.1
|
9 |
+
app_file: run.py
|
|
|
10 |
pinned: false
|
11 |
---
|
run.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 prophet import Prophet
|
7 |
+
pd.options.plotting.backend = "plotly"
|
8 |
+
|
9 |
+
def get_forecast(lib, time):
|
10 |
+
|
11 |
+
data = pypistats.overall(lib, total=True, format="pandas")
|
12 |
+
data = data.groupby("category").get_group("with_mirrors").sort_values("date")
|
13 |
+
start_date = date.today() - relativedelta(months=int(time.split(" ")[0]))
|
14 |
+
df = data[(data['date'] > str(start_date))]
|
15 |
+
|
16 |
+
df1 = df[['date','downloads']]
|
17 |
+
df1.columns = ['ds','y']
|
18 |
+
|
19 |
+
m = Prophet()
|
20 |
+
m.fit(df1)
|
21 |
+
future = m.make_future_dataframe(periods=90)
|
22 |
+
forecast = m.predict(future)
|
23 |
+
fig1 = m.plot(forecast)
|
24 |
+
return fig1
|
25 |
+
|
26 |
+
with gr.Blocks() as demo:
|
27 |
+
gr.Markdown(
|
28 |
+
"""
|
29 |
+
**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).
|
30 |
+
""")
|
31 |
+
with gr.Row():
|
32 |
+
lib = gr.Dropdown(["pandas", "scikit-learn", "torch", "prophet"], label="Library", value="pandas")
|
33 |
+
time = gr.Dropdown(["3 months", "6 months", "9 months", "12 months"], label="Downloads over the last...", value="12 months")
|
34 |
+
|
35 |
+
plt = gr.Plot()
|
36 |
+
|
37 |
+
lib.change(get_forecast, [lib, time], plt, queue=False)
|
38 |
+
time.change(get_forecast, [lib, time], plt, queue=False)
|
39 |
+
demo.load(get_forecast, [lib, time], plt, queue=False)
|
40 |
+
|
41 |
+
demo.launch()
|