import gradio as gr import joblib from PIL import Image # Load already saved pipelines best_model_cs = joblib.load("modelCS_V3.pkl") best_model_co2 = joblib.load("modelCO2_V3.pkl") # Prediction function for compressive strength model def make_prediction(Fly_ash, GGBS_GGBFS, Fine_aggregate, Na2SiO3_solution, NaOH_solution, NaOH_concentration, Superplasticiser, Curing_temperature, Curing_Period, Testing_Age): predt_cs = best_model_cs.predict([[Fly_ash, GGBS_GGBFS, Fine_aggregate, Na2SiO3_solution, NaOH_solution, NaOH_concentration, Superplasticiser, Curing_temperature, Curing_Period, Testing_Age]]) predt_co2 = best_model_co2.predict([[Fly_ash, GGBS_GGBFS, Fine_aggregate, Na2SiO3_solution, NaOH_solution, NaOH_concentration, Superplasticiser, Curing_temperature, Curing_Period, Testing_Age]]) value_cs = round(predt_cs[0], 3) value_co2 = round(predt_co2[0], 3) image_component = gr.Image("MOO results_V3.png", label="multi-objective optimization", type="pil") return value_cs, value_co2, image_component, # Inputs for the models inputs = [ gr.Slider(100, 961.0, label='Fly ash (Kg/m³) | Choose a value between 100 and 961', info="Amount of Fly ash (Kg/m³)"), gr.Slider(100, 711.0, label='GGBS or GGBFS (Kg/m³) | Choose a value between 100 and 711', info="Amount of Ground Granulated Blast Furnace Slag(Kg/m³)"), gr.Slider(300, 1956.0, label='Fine aggregate (Kg/m³) | Choose a value between 300 and 1956', info="Amount of Fine aggregate (Kg/m³)"), gr.Slider(14, 531.0, label='Na₂SiO₃ solution (Kg/m³) | Choose a value between 14 and 531', info="Amount of Sodium Silicate solution (Kg/m³)"), gr.Slider(12, 284.44, label='NaOH solution (Kg/m³) | Choose a value between 12 and 284.44', info="Amount of Sodium Hydroxide solution (Kg/m³)"), gr.Slider(3, 16.0, label='NaOH concentration (M) | Choose a value between 3 and 16', info="Sodium Hydroxide concentration (M)"), gr.Slider(0, 35.55, label='Superplasticiser (kg/m³) | Choose a value between 0 and 35.55', info="Amount of Superplasticiser (kg/m³)"), gr.Slider(20, 120, label='Curing temperature (°C) | Choose a value between 20 and 120'), gr.Slider(1, 90, label='Curing Period (days) | Choose a value between 1 and 90', info="For curing temperature more than 30 °C the curing period should be maximum of 3 days"), gr.Slider(1, 180, label='Testing Age (days) | Choose a value between 1 and 180', info="For curing temperature less than 30 °C the testing age should be equal to the curing period"), ] # Outputs for both models outputs = [ gr.Textbox(label="Compressive strength (MPa)"), gr.Textbox(label="CO₂ footprint (Kg/m³)"), gr.Image(label="multi-objective optimization for geopolymer mortar"), ] # Create one interface for both models app = gr.Interface( fn=make_prediction, inputs=inputs, outputs=outputs, title="Alkali-Activated Mortar Compressive Strength Prediction Using Machine Learning with Multi-objective Optimization", description="Developed by Mohamed Rabieᵃ, Mohamed Ibrahimᵇ, Usama Ebeadᵇ and Ibrahim Shaabanᵃ\n\nᵃUniversity of West London\n\nᵇQatar University \n\nContact: (mohamed.rabie@uwl.ac.uk ; mohamedrabie26@gmail.com)\n\nUse the sliders below to insert mix design quantity and click the submit button to make your prediction." ) app.launch(share=False)