Getting this error
Please Help
I'm enclosing my code here
from typing import List
import pandas as pd
from matplotlib import pyplot as plt
import statsmodels.api as sm
import pickle
from statsmodels.tsa.seasonal import seasonal_decompose
from statsmodels.tsa.holtwinters import SimpleExpSmoothing
from statsmodels.tsa.holtwinters import ExponentialSmoothing
from shiny.types import FileInfo, NavSetArg
from shiny import *
from shiny.ui import h4
from sklearn.metrics import mean_squared_error
from sklearn.metrics import mean_absolute_error
from math import sqrt
def nav_controls(orefix: str) -> List[NavSetArg]:
return [
ui.nav("Dataset",
ui.panel_main(ui.output_ui("datasetview")),
ui.output_plot("plot"),
),
ui.nav("Upload the Test File",
ui.panel_title("Prediction System"),
ui.input_file("file1", "Choose a file to upload:", accept=[".csv"], multiple=False),
ui.panel_main(ui.output_ui("testdataupload")),
ui.output_plot("plotprediction"),
),
ui.nav("Performance Matrics",
ui.panel_title("Performance of the Prediction"),
ui.panel_main(ui.output_ui("performancermse")),
ui.panel_main(ui.output_ui("performanceamse")),
),
]
app_ui = ui.page_navbar(
*nav_controls("page_navbar"),
title="Prediction System",
bg="#0062cc",
inverse=True,
id="navbar_id",
footer=ui.div(
{"style": "width:80%;margin: 0 auto"},
ui.tags.style(
"""
h4 {
margin-top: 3em;
}
"""
),
)
)
def server(input, output, session):
df = pd.read_csv('pred/datapred.csv', index_col='date', parse_dates=True)
df.sort_index(inplace=True)
with open('pred/prediction_model', 'rb') as f:
pmodel = pickle.load(f)
@output
@render.ui
def datasetview():
return ui.HTML(df.head().to_html(classes="table table-stripped"))
@output
@render.plot(alt="Line Graph")
def plot():
df[['amount']].plot(title="Sales Data")
@output
@render.ui
def testdataupload():
if input.file1() is None:
return "Please upload a file test the prediction (one column with date and another with amount)"
f: list[FileInfo] = input.file1()
testfile = pd.read_csv(f[0]["datapath"], index_col='date', parse_dates=True)
testfile.sort_index(inplace=True)
testfile['Holt_Winter_Prediction'] = pmodel.forecast(len(testfile))
testfile.to_csv(r'pred/testfile.csv')
return ui.HTML(testfile.to_html(classes="table table-stripped"))
@output
@render.plot(alt="Line Graph")
def plotprediction():
testfile = pd.read_csv('pred/testfile.csv', index_col='date', parse_dates=True)
testfile[['amount','Holt_Winter_Prediction']].plot(title="Holt Winter Forecast")
@output
@render.ui
def performancermse():
testfile = pd.read_csv('pred/testfile.csv', index_col='date', parse_dates=True)
rms = sqrt(mean_squared_error(testfile.amount, testfile.Holt_Winter_Prediction))
msg = "Root Mean Square Error (RMSE) is %f " %(rms)
return msg
@output
@render.ui
def performanceamse():
testfile = pd.read_csv('pred/testfile.csv', index_col='date', parse_dates=True)
rms = mean_absolute_error(testfile.amount, testfile.Holt_Winter_Prediction)
msg = "Absolute Mean Square Error is %f " %(rms)
return msg
app = App(app_ui, server)