fadzwan commited on
Commit
f00a83b
1 Parent(s): 16f35f5

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import joblib
3
+ import numpy as np
4
+
5
+ # Load the trained model, scaler, and PCA
6
+ regressor = joblib.load('slump_regressor.pkl')
7
+ scaler = joblib.load('scaler.pkl')
8
+
9
+ def preprocess_data(X):
10
+ # Load the trained scaler and PCA
11
+ scaler = joblib.load('scaler.pkl')
12
+ pca = joblib.load('pca.pkl')
13
+
14
+ # Check if the input has 8 features
15
+ if X.shape[1] != 8:
16
+ raise ValueError("Input data should have 8 features.")
17
+
18
+ # Scale the input data using the loaded scaler
19
+ X_scaled = scaler.transform(X)
20
+
21
+ # Apply PCA using the loaded PCA transformer
22
+ X_pca = pca.transform(X_scaled)
23
+
24
+ return X_pca
25
+
26
+ def predict_slump_app():
27
+ # Get the input values from the user
28
+ cement = st.number_input("Cement (kg/m^3)", min_value=0.0, step=0.1)
29
+ blast_furnace_slag = st.number_input("Blast Furnace Slag (kg/m^3)", min_value=0.0, step=0.1)
30
+ fly_ash = st.number_input("Fly Ash (kg/m^3)", min_value=0.0, step=0.1)
31
+ water = st.number_input("Water (kg/m^3)", min_value=0.0, step=0.1)
32
+ superplasticizer = st.number_input("Superplasticizer (kg/m^3)", min_value=0.0, step=0.1)
33
+ coarse_aggregate = st.number_input("Coarse Aggregate (kg/m^3)", min_value=0.0, step=0.1)
34
+ fine_aggregate = st.number_input("Fine Aggregate (kg/m^3)", min_value=0.0, step=0.1)
35
+ flow = st.number_input("FLOW (cm)", min_value=0.0, step=0.1)
36
+
37
+ # Prepare the input data
38
+ X = np.array([[cement, blast_furnace_slag, fly_ash, water, superplasticizer, coarse_aggregate, fine_aggregate, flow]])
39
+
40
+ # Preprocess the data
41
+ X_preprocessed = preprocess_data(X)
42
+
43
+ # Make the prediction
44
+ slump_prediction = regressor.predict(X_preprocessed)[0]
45
+
46
+ return slump_prediction
47
+
48
+ def main():
49
+ st.set_page_config(page_title="Concrete Slump Strength Prediction")
50
+ st.title("Concrete Slump Strength Prediction")
51
+ st.write("Enter the concrete mix parameters to predict the slump.")
52
+
53
+ slump_prediction = predict_slump_app()
54
+ st.subheader("Predicted Slump Strength:")
55
+ st.write(f"{slump_prediction:.2f} MPA")
56
+
57
+ if __name__ == '__main__':
58
+ main()