| import gradio as gr | |
| import pandas as pd | |
| import Generate | |
| import plotly.express as px | |
| example_df_aircomp=pd.read_csv('data/aircompressordata.csv') | |
| example_df_ener=pd.read_csv('data/energymeter.csv') | |
| example_df_boiler=pd.read_csv('data/Boiler1.csv') | |
| demo=gr.Blocks(title="EcoForecast") | |
| def pred_air(date): | |
| preds=Generate.inference_Aircomp(date,example_df_aircomp) | |
| return preds | |
| def pred_ener(date): | |
| preds=Generate.inference_Energy(date,example_df_ener) | |
| return preds | |
| def pred_boiler(date): | |
| preds=Generate.inference_boiler(date,example_df_boiler) | |
| return preds | |
| def upload_file(files): | |
| file_paths = [file.name for file in files] | |
| return file_paths | |
| with demo: | |
| gr.Markdown("Tool for predicting the next seven days of data in the future using the last 200 points of data incoming") | |
| with gr.Tabs(): | |
| with gr.TabItem("Air compressor data"): | |
| with gr.Row(): | |
| Air_input=gr.Text(placeholder="Enter date and like the example only",show_label=False) | |
| air_dataframe_input=gr.Dataframe(example_df_aircomp.head(100)) | |
| Air_dataframe_output=gr.Dataframe() | |
| with gr.Column(): | |
| Aircomp_output_btn=gr.Button("Forecast") | |
| Air_plot_forecast=gr.Button("Plot") | |
| Air_plots=gr.Plot() | |
| with gr.TabItem("Energymeter data"): | |
| with gr.Row(): | |
| ener_input=gr.Text(placeholder="Enter the date and time in example format only",show_label=False) | |
| ener_dataframe_input=gr.Dataframe(example_df_ener.head(100)) | |
| Ener_dataframe_output=gr.Dataframe() | |
| with gr.Column(): | |
| Energy_output_btn=gr.Button("Forecast") | |
| Ener_plot_forecast=gr.Button("Plot") | |
| Ener_plots=gr.Plot() | |
| with gr.TabItem("Boiler data"): | |
| with gr.Row(): | |
| boiler_input=gr.Text(placeholder="Enter the date and time in example format only",show_label=False) | |
| boiler_dataframe_input=gr.Dataframe(example_df_boiler.head(100)) | |
| boiler_dataframe_output=gr.Dataframe() | |
| with gr.Column(): | |
| Boiler_output_btn=gr.Button("Forecast") | |
| boiler_plot_forecast=gr.Button("Plot") | |
| boil_plots=gr.Plot() | |
| with gr.TabItem("Upload data"): | |
| file_output = gr.File() | |
| upload_button = gr.UploadButton("Click to Upload a File", file_types=["csv"], file_count="multiple") | |
| upload_button.upload(upload_file, upload_button, file_output) | |
| def plotg_air(dataframe): | |
| fig=px.line(dataframe,x='timestamp',y=dataframe.columns, | |
| hover_data={"timestamp":"|%B %d, %Y"}, | |
| title="Predictions") | |
| fig.update_xaxes( | |
| dtick="D1", | |
| tickformat="%b\n%Y" | |
| ) | |
| return fig | |
| def plotg_ener(dataframe): | |
| fig=px.line(dataframe,x='parameter_timestamp',y=dataframe.columns, | |
| hover_data={"parameter_timestamp":"|%B %d, %Y"}, | |
| title="Predictions") | |
| fig.update_xaxes( | |
| dtick="D1", | |
| tickformat="%b\n%Y" | |
| ) | |
| return fig | |
| def plotg_boiler(dataframe): | |
| fig=px.line(dataframe,x='DateString',y=dataframe.columns, | |
| hover_data={"DateString":"|%B %d, %Y"}, | |
| title="Predictions") | |
| fig.update_xaxes( | |
| dtick="D1", | |
| tickformat="%b\n%Y" | |
| ) | |
| return fig | |
| Aircomp_output_btn.click(pred_air,inputs=Air_input,outputs=Air_dataframe_output) | |
| Energy_output_btn.click(pred_ener,inputs=ener_input,outputs=Ener_dataframe_output) | |
| Boiler_output_btn.click(pred_boiler,inputs=boiler_input,outputs=boiler_dataframe_output) | |
| Air_plot_forecast.click(plotg_air,inputs=Air_dataframe_output,outputs=Air_plots) | |
| Ener_plot_forecast.click(plotg_ener,inputs=Ener_dataframe_output,outputs=Ener_plots) | |
| boiler_plot_forecast.click(plotg_boiler,inputs=boiler_dataframe_output,outputs=boil_plots) | |
| demo.launch(share=True) |