Skip to content

Instantly share code, notes, and snippets.

@erikbern
Created July 29, 2022 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikbern/6af5c10083daeae77c8735d9fd0765f1 to your computer and use it in GitHub Desktop.
Save erikbern/6af5c10083daeae77c8735d9fd0765f1 to your computer and use it in GitHub Desktop.
Run Prophet inside Modal
import io
import modal
stub = modal.Stub(image=modal.DebianSlim().pip_install(["prophet"]))
@stub.function
def run():
import pandas as pd
from prophet import Prophet
from matplotlib import pyplot
df = pd.read_csv('https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_peyton_manning.csv')
df.head()
m = Prophet()
m.fit(df)
future = m.make_future_dataframe(periods=365)
future.tail()
forecast = m.predict(future)
forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail()
fig1 = m.plot(forecast)
buf = io.BytesIO()
pyplot.savefig(buf)
return buf.getvalue()
if __name__ == "__main__":
with stub.run():
data = run()
with open("prophet.png", "wb") as f:
f.write(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment