Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,28 +7,28 @@ model = joblib.load('mushroom_classifier.pkl')
|
|
7 |
mappings = joblib.load('mappings.pkl')
|
8 |
|
9 |
feature_options = {
|
10 |
-
'cap-shape': {'
|
11 |
-
'cap-surface': {'
|
12 |
-
'cap-color': {'
|
13 |
-
'bruises': {'
|
14 |
-
'odor': {'
|
15 |
-
'gill-attachment': {'
|
16 |
-
'gill-spacing': {'
|
17 |
-
'gill-size': {'
|
18 |
-
'gill-color': {'
|
19 |
-
'stalk-shape': {'
|
20 |
-
'stalk-root': {'
|
21 |
-
'stalk-surface-above-ring': {'
|
22 |
-
'stalk-surface-below-ring': {'
|
23 |
-
'stalk-color-above-ring': {'
|
24 |
-
'stalk-color-below-ring': {'
|
25 |
-
'veil-type': {'
|
26 |
-
'veil-color': {'
|
27 |
-
'ring-number': {'
|
28 |
-
'ring-type': {'
|
29 |
-
'spore-print-color': {'
|
30 |
-
'population': {'
|
31 |
-
'habitat': {'
|
32 |
}
|
33 |
|
34 |
# def predict_mushroom(features):
|
@@ -37,29 +37,34 @@ feature_options = {
|
|
37 |
# prediction = model.predict(input_df)
|
38 |
# return 'Poisonous' if prediction[0] == 1 else 'Edible'
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
44 |
|
45 |
-
# Convert
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
|
|
49 |
else:
|
50 |
-
raise ValueError(f"
|
51 |
|
52 |
-
# Convert the numerical features into a DataFrame
|
53 |
input_df = pd.DataFrame([numerical_features])
|
54 |
-
|
55 |
-
#
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
|
64 |
demo = gr.Interface(
|
65 |
fn=predict_mushroom,
|
|
|
7 |
mappings = joblib.load('mappings.pkl')
|
8 |
|
9 |
feature_options = {
|
10 |
+
'cap-shape': {'b': 'bell', 'c': 'conical', 'x': 'convex', 'f': 'flat', 'k': 'knobbed', 's': 'sunken'},
|
11 |
+
'cap-surface': {'f': 'fibrous', 'g': 'grooves', 'y': 'scaly', 's': 'smooth'},
|
12 |
+
'cap-color': {'n': 'brown', 'b': 'buff', 'c': 'cinnamon', 'g': 'gray', 'r': 'green', 'p': 'pink', 'u': 'purple', 'e': 'red', 'w': 'white', 'y': 'yellow'},
|
13 |
+
'bruises': {'t': 'bruises', 'f': 'no'},
|
14 |
+
'odor': {'a': 'almond', 'l': 'anise', 'c': 'creosote', 'y': 'fishy', 'f': 'foul', 'm': 'musty', 'n': 'none', 'p': 'pungent', 's': 'spicy'},
|
15 |
+
'gill-attachment': {'a': 'attached', 'd': 'descending', 'f': 'free', 'n': 'notched'},
|
16 |
+
'gill-spacing': {'c': 'close', 'w': 'crowded', 'd': 'distant'},
|
17 |
+
'gill-size': {'b': 'broad', 'n': 'narrow'},
|
18 |
+
'gill-color': {'k': 'black', 'n': 'brown', 'b': 'buff', 'h': 'chocolate', 'g': 'gray', 'r': 'green', 'o': 'orange', 'p': 'pink', 'u': 'purple', 'e': 'red', 'w': 'white', 'y': 'yellow'},
|
19 |
+
'stalk-shape': {'e': 'enlarging', 't': 'tapering'},
|
20 |
+
'stalk-root': {'b': 'bulbous', 'c': 'club', 'u': 'cup', 'e': 'equal', 'z': 'rhizomorphs', 'r': 'rooted', '?': 'missing'},
|
21 |
+
'stalk-surface-above-ring': {'f': 'fibrous', 'y': 'scaly', 'k': 'silky', 's': 'smooth'},
|
22 |
+
'stalk-surface-below-ring': {'f': 'fibrous', 'y': 'scaly', 'k': 'silky', 's': 'smooth'},
|
23 |
+
'stalk-color-above-ring': {'n': 'brown', 'b': 'buff', 'c': 'cinnamon', 'g': 'gray', 'o': 'orange', 'p': 'pink', 'e': 'red', 'w': 'white', 'y': 'yellow'},
|
24 |
+
'stalk-color-below-ring': {'n': 'brown', 'b': 'buff', 'c': 'cinnamon', 'g': 'gray', 'o': 'orange', 'p': 'pink', 'e': 'red', 'w': 'white', 'y': 'yellow'},
|
25 |
+
'veil-type': {'p': 'partial', 'u': 'universal'},
|
26 |
+
'veil-color': {'n': 'brown', 'o': 'orange', 'w': 'white', 'y': 'yellow'},
|
27 |
+
'ring-number': {'n': 'none', 'o': 'one', 't': 'two'},
|
28 |
+
'ring-type': {'c': 'cobwebby', 'e': 'evanescent', 'f': 'flaring', 'l': 'large', 'n': 'none', 'p': 'pendant', 's': 'sheathing', 'z': 'zone'},
|
29 |
+
'spore-print-color': {'k': 'black', 'n': 'brown', 'b': 'buff', 'h': 'chocolate', 'r': 'green', 'o': 'orange', 'u': 'purple', 'w': 'white', 'y': 'yellow'},
|
30 |
+
'population': {'a': 'abundant', 'c': 'clustered', 'n': 'numerous', 's': 'scattered', 'v': 'several', 'y': 'solitary'},
|
31 |
+
'habitat': {'g': 'grasses', 'l': 'leaves', 'm': 'meadows', 'p': 'paths', 'u': 'urban', 'w': 'waste', 'd': 'woods'}
|
32 |
}
|
33 |
|
34 |
# def predict_mushroom(features):
|
|
|
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 string inputs to numerical values using mappings
|
47 |
+
numerical_features = {}
|
48 |
+
for feature, value in user_input.items():
|
49 |
+
if feature in mappings:
|
50 |
+
if value in mappings[feature]:
|
51 |
+
numerical_features[feature] = mappings[feature][value] # Map string to numerical value
|
52 |
+
else:
|
53 |
+
raise ValueError(f"Invalid value '{value}' for feature '{feature}'.")
|
54 |
else:
|
55 |
+
raise ValueError(f"Feature '{feature}' is not recognized.")
|
56 |
|
57 |
+
# Convert the numerical features into a DataFrame
|
58 |
input_df = pd.DataFrame([numerical_features])
|
59 |
+
|
60 |
+
# Predict using the trained model
|
61 |
+
prediction = model.predict(input_df)
|
62 |
+
|
63 |
+
# Interpret the prediction
|
64 |
+
if prediction[0] == 0:
|
65 |
+
return 'Edible'
|
66 |
+
else:
|
67 |
+
return 'Poisonous'
|
68 |
|
69 |
demo = gr.Interface(
|
70 |
fn=predict_mushroom,
|