| | import streamlit as st |
| | import pandas as pd |
| | import pickle |
| | import matplotlib.pyplot as plt |
| |
|
| | |
| | |
| | |
| | MODEL_PATH = "prophet_model.pkl" |
| |
|
| | try: |
| | with open(MODEL_PATH, "rb") as f: |
| | model = pickle.load(f) |
| | st.success("β
Loaded saved Prophet model.") |
| | except FileNotFoundError: |
| | model = None |
| | st.warning("β No saved model found. You can still upload CSV for chart display.") |
| |
|
| | |
| | |
| | |
| | st.title("π Prophet Forecast Viewer") |
| | uploaded_file = st.file_uploader("Upload your CSV file", type=["csv"]) |
| |
|
| | if uploaded_file is not None: |
| | df = pd.read_csv(uploaded_file) |
| |
|
| | st.subheader("Data Preview") |
| | st.write(df.head()) |
| |
|
| | |
| | if model is not None: |
| | try: |
| | |
| | df = df.rename(columns={df.columns[0]: 'ds'}) |
| | df['ds'] = pd.to_datetime(df['ds']) |
| |
|
| | predictions = model.predict(df) |
| | st.subheader("Predictions") |
| | st.write(predictions[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].head()) |
| |
|
| | |
| | fig, ax = plt.subplots(figsize=(10, 5)) |
| | ax.plot(df['ds'], predictions['yhat'], label="Forecast", color="blue") |
| | ax.fill_between(df['ds'], predictions['yhat_lower'], predictions['yhat_upper'], alpha=0.2) |
| | ax.set_title("Forecast Chart") |
| | ax.set_xlabel("Date") |
| | ax.set_ylabel("Value") |
| | ax.legend() |
| | st.pyplot(fig) |
| |
|
| | except Exception as e: |
| | st.error(f"Prediction failed: {e}") |
| |
|
| | else: |
| | st.info("π Please upload a CSV file to begin.") |
| |
|