anasmkh commited on
Commit
5bb9cf2
·
verified ·
1 Parent(s): cc2a1c8
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -25,23 +25,23 @@ numerical_inputs = {}
25
  categorical_inputs = {}
26
 
27
  try:
28
- numerical_features = list(scaler.feature_names_in_)
29
  categorical_features = list(label_encoders.keys())
30
  except AttributeError:
31
  st.error("Scaler or encoders are not properly loaded.")
32
  st.stop()
33
 
 
34
  for feature in numerical_features:
35
- numerical_inputs[feature] = st.number_input(f"Enter {feature}", value=0.0)
36
 
37
  for feature in categorical_features:
38
- if label_encoders[feature].classes_.size > 0:
39
  categorical_inputs[feature] = st.selectbox(f"Select {feature}", label_encoders[feature].classes_)
40
  else:
41
  st.error(f"Label encoder for {feature} is empty.")
42
  st.stop()
43
 
44
-
45
  if st.button("Predict"):
46
  try:
47
  for feature in categorical_inputs:
@@ -58,3 +58,4 @@ if st.button("Predict"):
58
 
59
  except Exception as e:
60
  st.error(f"Prediction error: {e}")
 
 
25
  categorical_inputs = {}
26
 
27
  try:
28
+ numerical_features = list(scaler.feature_names_in_)
29
  categorical_features = list(label_encoders.keys())
30
  except AttributeError:
31
  st.error("Scaler or encoders are not properly loaded.")
32
  st.stop()
33
 
34
+ # ✅ FIXED: Ensure numerical inputs always have valid default values
35
  for feature in numerical_features:
36
+ numerical_inputs[feature] = st.number_input(f"Enter {feature}", value=0.0, step=0.1, format="%.2f")
37
 
38
  for feature in categorical_features:
39
+ if label_encoders[feature].classes_.size > 0:
40
  categorical_inputs[feature] = st.selectbox(f"Select {feature}", label_encoders[feature].classes_)
41
  else:
42
  st.error(f"Label encoder for {feature} is empty.")
43
  st.stop()
44
 
 
45
  if st.button("Predict"):
46
  try:
47
  for feature in categorical_inputs:
 
58
 
59
  except Exception as e:
60
  st.error(f"Prediction error: {e}")
61
+