import streamlit as st import joblib import numpy as np # Load the trained model, scaler, and PCA regressor = joblib.load('slump_regressor.pkl') scaler = joblib.load('scaler.pkl') def preprocess_data(X): # Load the trained scaler and PCA scaler = joblib.load('scaler.pkl') pca = joblib.load('pca.pkl') # Check if the input has 8 features if X.shape[1] != 8: raise ValueError("Input data should have 8 features.") # Scale the input data using the loaded scaler X_scaled = scaler.transform(X) # Apply PCA using the loaded PCA transformer X_pca = pca.transform(X_scaled) return X_pca def predict_slump_app(): # Get the input values from the user cement = st.number_input("Cement (kg/m^3)", min_value=0.0, step=0.1) blast_furnace_slag = st.number_input("Blast Furnace Slag (kg/m^3)", min_value=0.0, step=0.1) fly_ash = st.number_input("Fly Ash (kg/m^3)", min_value=0.0, step=0.1) water = st.number_input("Water (kg/m^3)", min_value=0.0, step=0.1) superplasticizer = st.number_input("Superplasticizer (kg/m^3)", min_value=0.0, step=0.1) coarse_aggregate = st.number_input("Coarse Aggregate (kg/m^3)", min_value=0.0, step=0.1) fine_aggregate = st.number_input("Fine Aggregate (kg/m^3)", min_value=0.0, step=0.1) flow = st.number_input("FLOW (cm)", min_value=0.0, step=0.1) # Prepare the input data X = np.array([[cement, blast_furnace_slag, fly_ash, water, superplasticizer, coarse_aggregate, fine_aggregate, flow]]) # Preprocess the data X_preprocessed = preprocess_data(X) # Make the prediction slump_prediction = regressor.predict(X_preprocessed)[0] return slump_prediction def main(): st.set_page_config(page_title="Concrete Slump Strength Prediction") st.title("Concrete Slump Strength Prediction") st.write("Enter the concrete mix parameters to predict the slump.") slump_prediction = predict_slump_app() st.subheader("Predicted Slump Strength:") st.write(f"{slump_prediction:.2f} MPA") if __name__ == '__main__': main()