import gradio as gr import pandas as pd from neuralprophet import NeuralProphet, set_log_level import io import warnings warnings.filterwarnings("ignore", category=UserWarning) set_log_level("ERROR") 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=30, n_lags=12, changepoints_range=5, num_hidden_layers=6, yearly_seasonality=True, n_changepoints=150, trend_reg_threshold=False, # Disable trend regularization threshold d_hidden=9, global_normalization=True, seasonality_reg=1, unknown_data_normalization=True, seasonality_mode="multiplicative", drop_missing=True, learning_rate=0.1, log_level="ERROR" ) m.fit(df, freq='D') future = m.make_future_dataframe(df, periods=30, n_historic_predictions=True) forecast = m.predict(future) def predict_vn_index(option=None): fig = m.plot(forecast) path = "forecast_plot.png" fig.savefig(path) return path if __name__ == "__main__": dropdown = gr.inputs.Dropdown(["VNIndex"], label="Choose an option", default="VNIndex") interface = gr.Interface(fn=predict_vn_index, inputs=dropdown, outputs="image", title="Dự báo VN Index 30 ngày tới") interface.launch(share=True)