fadzwan commited on
Commit
002d19a
·
verified ·
1 Parent(s): f071b6c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -18
app.py CHANGED
@@ -16,32 +16,43 @@ with open('pca.pkl', 'rb') as f:
16
  def preprocess_data(X):
17
  # Check if the input has 8 features
18
  if X.shape[1] != 8:
19
- raise ValueError("Input data should have 8 features.")
20
 
21
- # Scale the input data using the loaded scaler
22
- X_scaled = scaler.transform(X)
 
23
 
24
- # Apply PCA using the loaded PCA transformer
25
- X_pca = pca.transform(X_scaled)
26
 
27
- return X_pca
 
 
28
 
29
  def predict_slump_app():
30
- # Get the input values from the user
31
- cement = st.number_input("Cement (kg/m^3)", min_value=0.0, step=0.1)
32
- blast_furnace_slag = st.number_input("Blast Furnace Slag (kg/m^3)", min_value=0.0, step=0.1)
33
- fly_ash = st.number_input("Fly Ash (kg/m^3)", min_value=0.0, step=0.1)
34
- water = st.number_input("Water (kg/m^3)", min_value=0.0, step=0.1)
35
- superplasticizer = st.number_input("Superplasticizer (kg/m^3)", min_value=0.0, step=0.1)
36
- coarse_aggregate = st.number_input("Coarse Aggregate (kg/m^3)", min_value=0.0, step=0.1)
37
- fine_aggregate = st.number_input("Fine Aggregate (kg/m^3)", min_value=0.0, step=0.1)
38
- flow = st.number_input("FLOW (cm)", min_value=0.0, step=0.1)
39
 
40
  # Prepare the input data
 
 
 
 
41
  X = np.array([[cement, blast_furnace_slag, fly_ash, water, superplasticizer, coarse_aggregate, fine_aggregate, flow]])
42
 
43
  # Preprocess the data
44
- X_preprocessed = preprocess_data(X)
 
 
 
 
45
 
46
  # Make the prediction
47
  slump_prediction = regressor.predict(X_preprocessed)[0]
@@ -54,8 +65,9 @@ def main():
54
  st.write("Enter the concrete mix parameters to predict the slump.")
55
 
56
  slump_prediction = predict_slump_app()
57
- st.subheader("Predicted Slump Strength:")
58
- st.write(f"{slump_prediction:.2f} MPA")
 
59
 
60
  if __name__ == '__main__':
61
  main()
 
16
  def preprocess_data(X):
17
  # Check if the input has 8 features
18
  if X.shape[1] != 8:
19
+ raise ValueError("The input data should have 8 features (cement, blast furnace slag, fly ash, water, superplasticizer, coarse aggregate, fine aggregate, flow).")
20
 
21
+ try:
22
+ # Scale the input data using the loaded scaler
23
+ X_scaled = scaler.transform(X)
24
 
25
+ # Apply PCA using the loaded PCA transformer
26
+ X_pca = pca.transform(X_scaled)
27
 
28
+ return X_pca
29
+ except Exception as e:
30
+ raise ValueError(f"Error preprocessing the data: {str(e)}")
31
 
32
  def predict_slump_app():
33
+ with st.expander("Concrete Mix Parameters"):
34
+ cement = st.number_input("Cement (kg/m^3)", min_value=0.0, step=0.1)
35
+ blast_furnace_slag = st.number_input("Blast Furnace Slag (kg/m^3)", min_value=0.0, step=0.1)
36
+ fly_ash = st.number_input("Fly Ash (kg/m^3)", min_value=0.0, step=0.1)
37
+ water = st.number_input("Water (kg/m^3)", min_value=0.0, step=0.1)
38
+ superplasticizer = st.number_input("Superplasticizer (kg/m^3)", min_value=0.0, step=0.1)
39
+ coarse_aggregate = st.number_input("Coarse Aggregate (kg/m^3)", min_value=0.0, step=0.1)
40
+ fine_aggregate = st.number_input("Fine Aggregate (kg/m^3)", min_value=0.0, step=0.1)
41
+ flow = st.number_input("FLOW (cm)", min_value=0.0, step=0.1)
42
 
43
  # Prepare the input data
44
+ total_mix = cement + blast_furnace_slag + fly_ash + water
45
+ if total_mix > 1000:
46
+ raise ValueError("The total mix quantity should not exceed 1000 kg/m^3.")
47
+
48
  X = np.array([[cement, blast_furnace_slag, fly_ash, water, superplasticizer, coarse_aggregate, fine_aggregate, flow]])
49
 
50
  # Preprocess the data
51
+ try:
52
+ X_preprocessed = preprocess_data(X)
53
+ except ValueError as e:
54
+ st.error(str(e))
55
+ return None
56
 
57
  # Make the prediction
58
  slump_prediction = regressor.predict(X_preprocessed)[0]
 
65
  st.write("Enter the concrete mix parameters to predict the slump.")
66
 
67
  slump_prediction = predict_slump_app()
68
+ if slump_prediction is not None:
69
+ st.subheader("Predicted Slump Strength")
70
+ st.markdown(f"The predicted slump strength is **{slump_prediction:.2f} MPa**.")
71
 
72
  if __name__ == '__main__':
73
  main()