JohanBeytell commited on
Commit
8c695a5
·
verified ·
1 Parent(s): 80a4901

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -37,18 +37,18 @@ feature_options = {
37
  # prediction = model.predict(input_df)
38
  # return 'Poisonous' if prediction[0] == 1 else 'Edible'
39
 
40
- # Prediction function for Gradio
41
  def predict_mushroom(*inputs):
42
  # Map the inputs to feature names
43
  features = list(feature_options.keys())
44
  user_input = dict(zip(features, inputs))
45
 
46
- # Convert the string inputs (full names) directly to corresponding letters using the mappings
47
  numerical_features = {}
48
  for feature, value in user_input.items():
49
- if feature in mappings:
50
- # Reverse the mapping to find the corresponding letter
51
- inverse_mapping = {v: k for k, v in mappings[feature].items()}
52
  if value in inverse_mapping:
53
  numerical_features[feature] = inverse_mapping[value] # Map full name to letter
54
  else:
@@ -59,6 +59,9 @@ def predict_mushroom(*inputs):
59
  # Convert the numerical features into a DataFrame
60
  input_df = pd.DataFrame([numerical_features])
61
 
 
 
 
62
  # Predict using the trained model
63
  prediction = model.predict(input_df)
64
 
 
37
  # prediction = model.predict(input_df)
38
  # return 'Poisonous' if prediction[0] == 1 else 'Edible'
39
 
40
+ # Prediction function
41
  def predict_mushroom(*inputs):
42
  # Map the inputs to feature names
43
  features = list(feature_options.keys())
44
  user_input = dict(zip(features, inputs))
45
 
46
+ # Convert full names to letters using feature_options
47
  numerical_features = {}
48
  for feature, value in user_input.items():
49
+ if feature in feature_options:
50
+ # Reverse the feature_options dictionary to map full names to letter codes
51
+ inverse_mapping = {v: k for k, v in feature_options[feature].items()}
52
  if value in inverse_mapping:
53
  numerical_features[feature] = inverse_mapping[value] # Map full name to letter
54
  else:
 
59
  # Convert the numerical features into a DataFrame
60
  input_df = pd.DataFrame([numerical_features])
61
 
62
+ # Load the trained model
63
+ model = joblib.load('mushroom_classifier.pkl')
64
+
65
  # Predict using the trained model
66
  prediction = model.predict(input_df)
67