chEstyleU / app.py
masa729406's picture
Update app.py
763a979
raw
history blame
993 Bytes
import gradio as gr
import pandas as pd
from prophet import Prophet
def plot_forecast(example_name, period):
df = pd.read_csv(f'https://raw.githubusercontent.com/facebook/prophet/main/examples/example_{example_name}.csv')
df.columns = ['ds','y']
m = Prophet()
m.fit(df)
future = m.make_future_dataframe(periods=period)
forecast = m.predict(future)
fig = m.plot(forecast)
return fig
with gr.Blocks() as demo:
gr.Markdown(
"""
時系列予測モデルの結果
""")
with gr.Row():
example = gr.Dropdown(["air_passengers", "pedestrians_covid", "retail_sales"], label="データソース", value="air_passengers")
period = gr.Slider(25, 250, 25, step=25, label="予測期間")
plt = gr.Plot()
example.change(plot_forecast, [example,period], plt, queue=False)
period.change(plot_forecast, [example,period], plt, queue=False)
demo.load(plot_forecast, [example,period], plt, queue=False)
demo.launch()