import json import gradio as gr from gr_app2 import args, GradioApp demo = gr.Blocks(**args.block) with demo: app = GradioApp() md__title = gr.Markdown(**args.md__title) with gr.Row(): with gr.Column(): file__historical = gr.File(**args.file__historical) with gr.Column(): file__future = gr.File(**args.file__future) md__future = gr.Markdown(**args.md__future) with gr.Row(): btn__load_historical_demo = gr.Button("Load Demo Historical Data") btn__load_future_demo = gr.Button("Load Demo Future Data") with gr.Row(): number__n_predict = gr.Number( value=app.n_predict, **args.number__n_predict) number__window_length = gr.Number( value=app.window_length, **args.number__window_length ) textbox__target_column = gr.Textbox( value=app.target_column, **args.textbox__target_column ) number__n_predict.change( app.number__n_predict__change, [number__n_predict] ) number__window_length.change( app.number__window_length__change, [number__window_length] ) textbox__target_column.change( app.textbox__target_column__change, [textbox__target_column] ) # ---------- # # Data Views # # ---------- # with gr.Tabs(): with gr.Tab('Table View'): df__table_view = gr.Dataframe(**args.df__table_view) with gr.Tab('Chart View'): dropdown__chart_view_filter = gr.Dropdown( multiselect=True, label='Filter') plot__chart_view = gr.Plot() with gr.Tab('Seasonality and Auto Correlation'): dropdown__seasonality_decompose = gr.Dropdown( label='Please select column to decompose') with gr.Row(): plot__seasonality_decompose = gr.Plot() plot_acg_pacf = gr.Plot() with gr.Tab('Correlations'): btn__plot_correlation = gr.Button('Plot Correlations') plot__correlation = gr.Plot() btn__plot_correlation.click( app.btn__plot_correlation__click, [], [plot__correlation] ) with gr.Tab("Data Profile"): btn__profiling = gr.Button('Profile Data') md__profiling = gr.Markdown() plot__change_points = gr.Plot() dropdown__seasonality_decompose.change( app.dropdown__seasonality_decompose__change, [dropdown__seasonality_decompose], [plot__seasonality_decompose, plot_acg_pacf] ) btn__profiling.click( app.btn__profiling__click, [], [md__profiling, plot__change_points] ) # ---------------------- # # Fit data to forecaster # # ---------------------- # btn__fit_data = gr.Button(**args.btn__fit_data) # =========== # # Forecasting # # =========== # column__models = gr.Column(visible=True) with column__models: md__fit_ready = gr.Markdown(**args.md__fit_ready) md__forecast_data_info = gr.Markdown() # ------------- # # Model Configs # # ------------- # with gr.Row(): checkbox__round_results = gr.Checkbox( app.round_results, label='Round Results', interactive=True) checkbox__round_results.change( app.checkbox__round_results__change, [checkbox__round_results], [] ) gr.Markdown('## Models') # ------- # # XGBoost # # ------- # with gr.Tab('XGBoost'): with gr.Row(): checkbox__xgboost_cv = gr.Checkbox( app.xgboost_cv, label='Cross Validation') checkbox__xgboost_round = gr.Checkbox( app.xgboost.round_result, label='Round Result', interactive=True) checkbox__xgboost_round.change( app.checkbox__xgboost_round__change, [checkbox__xgboost_round], [] ) with gr.Row(): with gr.Column(): textbox__xgboost_params = gr.Textbox( interactive=True, value=app.xgboost_params) btn__set_xgboost_params = gr.Button("Set Params") json_xgboost_params = gr.JSON( value=app.xgboost_params, **args.json_xgboost_params) btn__set_xgboost_params.click( app.btn__set_xgboost_params__click, [textbox__xgboost_params], [json_xgboost_params]) btn__train_xgboost = gr.Button("Forecast with XGBoost Model") plot__xgboost_result = gr.Plot() with gr.Row(): df__xgboost_result = gr.Dataframe() file__xgboost_result = gr.File() btn__train_xgboost.click( app.btn__train_xgboost__click, [], [plot__xgboost_result, file__xgboost_result, df__xgboost_result]) # ------- # # Prophet # # ------- # with gr.Tab('Prophet'): gr.Markdown('Prophet') btn__forecast_with_prophet = gr.Button( **args.btn__forecast_with_prophet) plot__prophet_result = gr.Plot() with gr.Row(): df__prophet_result = gr.DataFrame() file__prophet_result = gr.File() btn__forecast_with_prophet.click( app.btn__forecast_with_prophet__click, [], [plot__prophet_result, file__prophet_result, df__prophet_result] ) # --------- # # Operators # # --------- # file__historical.upload( app.file__historical__upload, [file__historical], [df__table_view, dropdown__chart_view_filter, dropdown__seasonality_decompose, plot__chart_view]) file__future.upload( app.file__future__upload, [file__future], [df__table_view, dropdown__chart_view_filter, dropdown__seasonality_decompose, plot__chart_view, number__n_predict]) btn__fit_data.click( app.btn__fit_data__click, [], [ number__n_predict, number__window_length, file__historical, file__future, btn__fit_data, column__models, btn__load_historical_demo, btn__load_future_demo, md__forecast_data_info, ]) btn__load_historical_demo.click( app.btn__load_historical_demo__click, [], [df__table_view, dropdown__chart_view_filter, dropdown__seasonality_decompose, plot__chart_view,] ) btn__load_future_demo.click( app.btn__load_future_demo__click, [], [df__table_view, dropdown__chart_view_filter, dropdown__seasonality_decompose, plot__chart_view, number__n_predict] ) dropdown__chart_view_filter.change( app.dropdown__chart_view_filter__change, [dropdown__chart_view_filter], [plot__chart_view] ) demo.launch()