Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
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
|
47 |
numerical_features = {}
|
48 |
for feature, value in user_input.items():
|
49 |
-
if feature in
|
50 |
-
# Reverse the
|
51 |
-
inverse_mapping = {v: k for k, v in
|
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 |
|