CoolFace
Apppublic

mnds18/agentic-ts-forecasting-system

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
app.py104 linesDownload Raw Back to root
1import streamlit as st2import pandas as pd3import numpy as np4import plotly.graph_objs as go5import os6from sklearn.metrics import mean_absolute_error, mean_squared_error7 8# --- Page Configuration ---9st.set_page_config(10    page_title="Enterprise Time Series Forecaster",11    layout="wide",12    page_icon="๐Ÿ“ˆ"13)14 15# --- App Header ---16st.title("๐Ÿ“Š Agentic AI Powered Time Series Forecasting")17st.markdown("An intelligent forecasting dashboard powered by modular agents and Prophet.")18st.markdown("---")19 20# --- Sidebar Settings ---21st.sidebar.header("๐Ÿ“‚ Configuration")22data_path = "daily_sales.csv"23forecast_path = "forecast.csv"24 25# --- Load Data ---26@st.cache_data27def load_data():28    if os.path.exists(data_path):29        df = pd.read_csv(data_path)30        df['ds'] = pd.to_datetime(df['ds'])31        return df32    return pd.DataFrame()33 34@st.cache_data35def load_forecast():36    if os.path.exists(forecast_path):37        df = pd.read_csv(forecast_path)38        df['ds'] = pd.to_datetime(df['ds'])39        return df40    return pd.DataFrame()41 42df = load_data()43forecast_df = load_forecast()44 45if df.empty or forecast_df.empty:46    st.error("โŒ Required data not found. Please run the pipeline first.")47    st.stop()48 49# --- Metric Comparison ---50st.subheader("๐Ÿ“‰ Key Forecast Metrics")51actual = df['y'].values[-60:]52forecast = forecast_df['yhat'].values[-60:]53 54if len(actual) == len(forecast):55    mae = mean_absolute_error(actual, forecast)56    rmse = np.sqrt(mean_squared_error(actual, forecast))57    mape = np.mean(np.abs((actual - forecast) / actual)) * 10058 59    col1, col2, col3 = st.columns(3)60    col1.metric("MAE", f"{mae:.2f}")61    col2.metric("RMSE", f"{rmse:.2f}")62    col3.metric("MAPE", f"{mape:.2f}%")63else:64    st.warning("โš ๏ธ Could not calculate error metrics โ€” mismatch in actual vs forecast data length.")65 66# --- Interactive Forecast Plot ---67st.subheader("๐Ÿ“ˆ Forecast Chart")68fig = go.Figure()69 70fig.add_trace(go.Scatter(71    x=df['ds'], y=df['y'], mode='lines', name='Actual Sales',72    line=dict(color='royalblue')73))74 75fig.add_trace(go.Scatter(76    x=forecast_df['ds'], y=forecast_df['yhat'], mode='lines', name='Forecast',77    line=dict(color='orange', dash='dash')78))79 80fig.update_layout(81    height=500,82    margin=dict(l=30, r=30, t=30, b=30),83    xaxis_title="Date",84    yaxis_title="Sales",85    template="plotly_white",86    hovermode="x unified"87)88 89st.plotly_chart(fig, use_container_width=True)90 91# --- Expandable Raw Data Section ---92with st.expander("๐Ÿงพ View Raw Input Data"):93    st.dataframe(df.tail(10), use_container_width=True)94 95with st.expander("๐Ÿ”ฎ View Forecast Output (Next 60 Days)"):96    st.dataframe(forecast_df.tail(60).reset_index(drop=True), use_container_width=True)97 98# --- Footer ---99st.markdown("---")100st.markdown(101    "๐Ÿš€ Built by **Mrig Debsarma** | "102    "Powered by **LangChain-style Agents**, **Prophet**, and **Streamlit**"103)104