JohanBeytell commited on
Commit
ae1ff75
·
verified ·
1 Parent(s): 2d47804

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -8
app.py CHANGED
@@ -18,10 +18,6 @@ feature_options = {
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'},
@@ -31,20 +27,52 @@ feature_options = {
31
  'habitat': {'g': 'grasses', 'l': 'leaves', 'm': 'meadows', 'p': 'paths', 'u': 'urban', 'w': 'waste', 'd': 'woods'}
32
  }
33
 
34
- def predict_mushroom(**features):
35
  numerical_features = {}
36
  for feature, value in features.items():
37
  if feature in mappings and value in mappings[feature]:
38
  numerical_features[feature] = mappings[feature][value]
39
  else:
40
- return "Invalid input detected."
41
 
42
  input_df = pd.DataFrame([numerical_features])
43
  prediction = model.predict(input_df)
44
  return "Edible" if prediction[0] == 0 else "Poisonous"
45
 
46
- dropdowns = [gr.Dropdown(choices=list(options.values()), label=feature.replace('-', ' ').capitalize()) for feature, options in feature_options.items()]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
- demo = gr.Interface(fn=predict_mushroom, inputs=dropdowns, outputs="text", title="Mushroom Classification", description="Select the characteristics of the mushroom to determine if it's edible or poisonous.")
 
 
 
 
 
 
 
49
 
50
  demo.launch()
 
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
  'veil-type': {'p': 'partial', 'u': 'universal'},
22
  'veil-color': {'n': 'brown', 'o': 'orange', 'w': 'white', 'y': 'yellow'},
23
  'ring-number': {'n': 'none', 'o': 'one', 't': 'two'},
 
27
  'habitat': {'g': 'grasses', 'l': 'leaves', 'm': 'meadows', 'p': 'paths', 'u': 'urban', 'w': 'waste', 'd': 'woods'}
28
  }
29
 
30
+ def predict_mushroom(features):
31
  numerical_features = {}
32
  for feature, value in features.items():
33
  if feature in mappings and value in mappings[feature]:
34
  numerical_features[feature] = mappings[feature][value]
35
  else:
36
+ return "Invalid input. Please check feature values."
37
 
38
  input_df = pd.DataFrame([numerical_features])
39
  prediction = model.predict(input_df)
40
  return "Edible" if prediction[0] == 0 else "Poisonous"
41
 
42
+ examples = [
43
+ { # Death Cap (Poisonous)
44
+ 'cap-shape': 'x', 'cap-surface': 's', 'cap-color': 'r', 'bruises': 'f', 'odor': 'p',
45
+ 'gill-attachment': 'f', 'gill-spacing': 'w', 'gill-size': 'n', 'gill-color': 'w',
46
+ 'stalk-shape': 'e', 'stalk-root': 'b', 'veil-type': 'p', 'veil-color': 'w',
47
+ 'ring-number': 'o', 'ring-type': 'p', 'spore-print-color': 'w', 'population': 'v', 'habitat': 'd'
48
+ },
49
+ { # Common Brown Mushroom (Edible)
50
+ 'cap-shape': 'x', 'cap-surface': 's', 'cap-color': 'n', 'bruises': 't', 'odor': 'a',
51
+ 'gill-attachment': 'f', 'gill-spacing': 'w', 'gill-size': 'b', 'gill-color': 'h',
52
+ 'stalk-shape': 'e', 'stalk-root': 'c', 'veil-type': 'p', 'veil-color': 'w',
53
+ 'ring-number': 'o', 'ring-type': 'p', 'spore-print-color': 'n', 'population': 'n', 'habitat': 'm'
54
+ },
55
+ { # Fly Agaric (Poisonous)
56
+ 'cap-shape': 'x', 'cap-surface': 'y', 'cap-color': 'e', 'bruises': 'f', 'odor': 'n',
57
+ 'gill-attachment': 'f', 'gill-spacing': 'w', 'gill-size': 'b', 'gill-color': 'w',
58
+ 'stalk-shape': 'e', 'stalk-root': 'b', 'veil-type': 'p', 'veil-color': 'w',
59
+ 'ring-number': 'o', 'ring-type': 'p', 'spore-print-color': 'w', 'population': 'v', 'habitat': 'd'
60
+ },
61
+ { # Oyster Mushroom (Edible)
62
+ 'cap-shape': 'x', 'cap-surface': 's', 'cap-color': 'w', 'bruises': 'f', 'odor': 'l',
63
+ 'gill-attachment': 'd', 'gill-spacing': 'c', 'gill-size': 'b', 'gill-color': 'w',
64
+ 'stalk-shape': 't', 'stalk-root': '?', 'veil-type': 'p', 'veil-color': 'w',
65
+ 'ring-number': 'n', 'ring-type': 'n', 'spore-print-color': 'u', 'population': 'c', 'habitat': 'd'
66
+ }
67
+ ]
68
 
69
+ demo = gr.Interface(
70
+ fn=predict_mushroom,
71
+ inputs=[gr.Dropdown(choices=list(options.keys()), label=key) for key, options in feature_options.items()],
72
+ outputs="text",
73
+ examples=[[v for v in example.values()] for example in examples],
74
+ title="MycoNom - Mushroom Classifier",
75
+ description="Select mushroom characteristics to predict if it's edible or poisonous. **Disclaimer:** This model is for **educational purposes only** and should not be used for real-life mushroom classification or any decision-making processes related to the consumption of mushrooms. While the model performs well on the provided dataset, it has not been thoroughly validated for real-world scenarios and may not accurately detect poisonous mushrooms in all conditions. Always consult an expert or use trusted resources when identifying mushrooms."
76
+ )
77
 
78
  demo.launch()