|
import streamlit as st |
|
import numpy as np |
|
import pickle |
|
from sklearn.linear_model import LinearRegression |
|
from sklearn.preprocessing import StandardScaler |
|
from sklearn.decomposition import PCA |
|
import joblib |
|
import pandas as pd |
|
|
|
def load_data(): |
|
X_train = pd.read_csv('preprocessed_slump.csv').values[:,:-1] |
|
|
|
y_train = pd.read_csv('preprocessed_slump.csv').values[:, -1] |
|
|
|
|
|
print("X_train",X_train.shape) |
|
print("y_train",y_train.shape) |
|
|
|
|
|
|
|
return X_train, y_train |
|
|
|
def load_model_artifacts(): |
|
with open('slump_regressor.pkl', 'rb') as f: |
|
regressor = pickle.load(f) |
|
with open('scaler.pkl', 'rb') as f: |
|
scaler = pickle.load(f) |
|
with open('pca.pkl', 'rb') as f: |
|
pca = pickle.load(f) |
|
return regressor, scaler, pca |
|
|
|
def save_model_artifacts(regressor, scaler, pca): |
|
with open('slump_regressor.pkl', 'wb') as f: |
|
pickle.dump(regressor, f, protocol=pickle.HIGHEST_PROTOCOL) |
|
with open('scaler.pkl', 'wb') as f: |
|
pickle.dump(scaler, f, protocol=pickle.HIGHEST_PROTOCOL) |
|
with open('pca.pkl', 'wb') as f: |
|
pickle.dump(pca, f, protocol=pickle.HIGHEST_PROTOCOL) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def predict_slump(cement, blast_furnace_slag, fly_ash, water, superplasticizer, coarse_aggregate, fine_aggregate, FLOW): |
|
|
|
X = np.array([[cement, blast_furnace_slag, fly_ash, water, superplasticizer, coarse_aggregate, fine_aggregate, FLOW]]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
regressor = joblib.load('slump_regressor.pkl') |
|
|
|
|
|
slump_prediction = regressor.predict(X)[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.") |
|
|
|
try: |
|
regressor, scaler, pca = load_model_artifacts() |
|
print("main regressor", regressor,'scaler',scaler,'pca',pca) |
|
except (FileNotFoundError, pickle.UnpicklingError): |
|
X_train, y_train = load_data() |
|
regressor = LinearRegression() |
|
regressor.fit(X_train, y_train) |
|
scaler = StandardScaler() |
|
scaler.fit(X_train) |
|
pca = PCA(n_components=4) |
|
pca.fit(scaler.transform(X_train)) |
|
save_model_artifacts(regressor, scaler, pca) |
|
|
|
|
|
cement = st.number_input("Cement (kg/m^3)", min_value=0.0, step=1.0) |
|
blast_furnace_slag = st.number_input("Blast Furnace Slag (kg/m^3)", min_value=0.0, step=1.0) |
|
fly_ash = st.number_input("Fly Ash (kg/m^3)", min_value=0.0, step=1.0) |
|
water = st.number_input("Water (kg/m^3)", min_value=0.0, step=1.0) |
|
superplasticizer = st.number_input("Superplasticizer (kg/m^3)", min_value=0.0, step=1.0) |
|
coarse_aggregate = st.number_input("Coarse Aggregate (kg/m^3)", min_value=0.0, step=1.0) |
|
fine_aggregate = st.number_input("Fine Aggregate (kg/m^3)", min_value=0.0, step=1.0) |
|
FLOW = st.number_input("FLOW (cm)", min_value=0.0, step=1.0) |
|
|
|
print('cement',cement,'blast_furnace_slag', blast_furnace_slag, 'fly_ash',fly_ash,'water', water, 'superplasticizer',superplasticizer, 'coarse_aggregate',coarse_aggregate, 'fine_aggregate',fine_aggregate, 'FLOW',FLOW) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if st.button("Predict Slump Strength"): |
|
slump_prediction = predict_slump(cement, blast_furnace_slag, fly_ash, water, superplasticizer, coarse_aggregate, fine_aggregate, FLOW) |
|
print('slump_prediction',slump_prediction) |
|
st.write(f"Predicted Slump Strength: {slump_prediction:.2f} MPA") |
|
|
|
|
|
st.title("Concrete Slump Strength Prediction and Sustainable Development Goals") |
|
|
|
st.write("""Concrete slump strength prediction is an important topic that can have implications for several Sustainable Development Goals (SDGs) set by the United Nations.""") |
|
|
|
col1, col2 = st.columns(2) |
|
|
|
with col1: |
|
st.subheader("SDG 9: Industry, Innovation, and Infrastructure") |
|
st.markdown(""" |
|
- Accurate prediction of concrete slump strength can help in the design and construction of more robust and resilient infrastructure. |
|
- Improved concrete strength prediction can lead to more efficient use of materials and resources, reducing waste and promoting sustainable construction practices. |
|
""") |
|
|
|
with col2: |
|
st.subheader("SDG 11: Sustainable Cities and Communities") |
|
st.markdown(""" |
|
- Reliable concrete slump strength prediction can contribute to the development of sustainable and resilient cities. |
|
- Accurate slump strength prediction can help in the planning and construction of affordable and accessible housing. |
|
""") |
|
|
|
if __name__ == '__main__': |
|
main() |
|
|
|
|
|
|
|
import streamlit as st |
|
|
|
|
|
|
|
|