import gradio as gr import pandas as pd from neuralprophet import NeuralProphet, set_log_level import warnings set_log_level("ERROR") warnings.filterwarnings("ignore", category=UserWarning) url = "VN Index Historical Data.csv" df = pd.read_csv(url) df = df[["Date", "Price"]] df = df.rename(columns={"Date": "ds", "Price": "y"}) df.fillna(method='ffill', inplace=True) df.dropna(inplace=True) m = NeuralProphet(n_forecasts= 3, n_lags=12, changepoints_range=1, num_hidden_layers=6, daily_seasonality= False, weekly_seasonality = False, yearly_seasonality = True, ar_reg=True, n_changepoints=150, trend_reg_threshold=True, d_hidden=9, global_normalization=True, global_time_normalization=True, seasonality_reg=1, unknown_data_normalization=True, seasonality_mode="multiplicative", drop_missing=True, learning_rate=0.1 ) m.fit(df, freq='M') future = m.make_future_dataframe(df, periods=30, n_historic_predictions=True) forecast = m.predict(future) def predict_vn_index(option=None): fig1 = m.plot(forecast) fig1_path = "forecast_plot1.png" fig1.savefig(fig1_path) # Add code to generate the second image (fig2) fig2 = m.plot_latest_forecast(forecast) # Replace this line with code to generate the second image fig2_path = "forecast_plot2.png" fig2.savefig(fig2_path) description = "The predictions are conducted by a Deep Learning AI algorithm, and data augmentation is performed by the AI Consultant team. Data is updated after 5 PM GMT+7 on trading days." disclaimer = "Please consider this as a reference only; the company holds no responsibility for your investment status." return fig1_path, fig2_path, description, disclaimer if __name__ == "__main__": dropdown = gr.inputs.Dropdown(["VNIndex"], label="Choose an option", default="VNIndex") outputs = [ gr.outputs.Image(type="filepath", label="The VN Index price history and forecast"), gr.outputs.Image(type="filepath", label="Forecasting the VN Index for the next 90 days"), gr.outputs.Textbox(label="Description"), gr.outputs.Textbox(label="Disclaimer") ] interface = gr.Interface(fn=predict_vn_index, inputs=dropdown, outputs=outputs, title="Forecasting the VN Index for the next 90 days") interface.launch()