JohanBeytell commited on
Commit
35814cf
·
verified ·
1 Parent(s): a087cbd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -4
app.py CHANGED
@@ -39,11 +39,26 @@ feature_options = {
39
 
40
  def predict_mushroom(*features):
41
  # Convert the feature names to a dictionary based on the order
42
- feature_names = list(feature_options.keys())
43
- numerical_features = {feature_names[i]: feature_options[feature_names[i]][value] for i, value in enumerate(features)}
44
-
 
 
 
 
 
 
 
 
45
  input_df = pd.DataFrame([numerical_features])
46
- prediction = model.predict(input_df)
 
 
 
 
 
 
 
47
  return 'Poisonous' if prediction[0] == 1 else 'Edible'
48
 
49
  demo = gr.Interface(
 
39
 
40
  def predict_mushroom(*features):
41
  # Convert the feature names to a dictionary based on the order
42
+ feature_names = list(mappings.keys())
43
+ numerical_features = {}
44
+
45
+ # Convert the string values to numerical values using the mappings
46
+ for i, feature in enumerate(features):
47
+ if feature in mappings[feature_names[i]]:
48
+ numerical_features[feature_names[i]] = mappings[feature_names[i]][feature]
49
+ else:
50
+ raise ValueError(f"Invalid value for feature '{feature_names[i]}': {feature}")
51
+
52
+ # Convert the numerical features into a DataFrame for the model
53
  input_df = pd.DataFrame([numerical_features])
54
+
55
+ # Ensure the data is in the right format
56
+ try:
57
+ prediction = model.predict(input_df)
58
+ except Exception as e:
59
+ raise ValueError(f"Error during prediction: {e}")
60
+
61
+ # Return the classification result based on the model output
62
  return 'Poisonous' if prediction[0] == 1 else 'Edible'
63
 
64
  demo = gr.Interface(