Srivastava commited on
Commit
e49a481
·
verified ·
1 Parent(s): 115a35a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -33
app.py CHANGED
@@ -2,6 +2,8 @@ from sklearn.preprocessing import LabelEncoder
2
  import pandas as pd
3
  import pickle
4
  import gradio as gr
 
 
5
  svc=pickle.load(open('svc.pickle','rb'))
6
  def predict_class(cap_shape, cap_surface, cap_color, bruises, odor, gill_attachment,
7
  gill_spacing, gill_size, gill_color, stalk_shape, stalk_root,
@@ -13,19 +15,49 @@ def predict_class(cap_shape, cap_surface, cap_color, bruises, odor, gill_attachm
13
  stalk_surface_above_ring, stalk_surface_below_ring, stalk_color_above_ring,
14
  stalk_color_below_ring, veil_color, ring_number, ring_type, spore_print_color,
15
  population, habitat]
16
- encoder=LabelEncoder()
17
- real_df=pd.read_csv('mushrooms.csv')
18
- real_df.drop(['class','veil-type'],axis=1,inplace=True)
19
- encoded_value=[]
20
  features = [ 'cap-shape', 'cap-surface', 'cap-color', 'bruises', 'odor',
21
  'gill-attachment', 'gill-spacing', 'gill-size', 'gill-color',
22
  'stalk-shape', 'stalk-root', 'stalk-surface-above-ring',
23
  'stalk-surface-below-ring', 'stalk-color-above-ring',
24
  'stalk-color-below-ring', 'veil-color', 'ring-number',
25
  'ring-type', 'spore-print-color', 'population', 'habitat']
26
- randomly_selected_values = ['s', 'y', 'g', 'f', 'c', 'a', 'w', 'n', 'b', 't', 'e', 's', 'k', 'o', 'y', 'w', 'o', 'f', 'r', 'y', 'p']
27
- random=pd.DataFrame([input_data],columns=features)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  for i in real_df.columns:
 
29
  encoder.fit_transform(real_df[i])
30
  encoded_value.append(encoder.transform(random[i])[0])
31
 
@@ -38,35 +70,29 @@ def predict_class(cap_shape, cap_surface, cap_color, bruises, odor, gill_attachm
38
 
39
 
40
 
41
-
42
- import gradio as gr
43
- input_features = {
44
- 'cap-shape': ['x', 'b', 's', 'f', 'k', 'c'],
45
- 'cap-surface': ['s', 'y', 'f', 'g'],
46
- 'cap-color': ['n', 'y', 'w', 'g', 'e', 'p', 'b', 'u', 'c', 'r'],
47
- 'bruises': ['t', 'f'],
48
- 'odor': ['p', 'a', 'l', 'n', 'f', 'c', 'y', 's', 'm'],
49
- 'gill-attachment': ['f', 'a'],
50
- 'gill-spacing': ['c', 'w'],
51
- 'gill-size': ['n', 'b'],
52
- 'gill-color': ['k', 'n', 'g', 'p', 'w', 'h', 'u', 'e', 'b', 'r', 'y', 'o'],
53
- 'stalk-shape': ['e', 't'],
54
- 'stalk-root': ['e', 'c', 'b', 'r', '?'],
55
- 'stalk-surface-above-ring': ['s', 'f', 'k', 'y'],
56
- 'stalk-surface-below-ring': ['s', 'f', 'y', 'k'],
57
- 'stalk-color-above-ring': ['w', 'g', 'p', 'n', 'b', 'e', 'o', 'c', 'y'],
58
- 'stalk-color-below-ring': ['w', 'p', 'g', 'b', 'n', 'e', 'y', 'o', 'c'],
59
- 'veil-color': ['w', 'n', 'o', 'y'],
60
- 'ring-number': ['o', 't', 'n'],
61
- 'ring-type': ['p', 'e', 'l', 'f', 'n'],
62
- 'spore-print-color': ['k', 'n', 'u', 'h', 'w', 'r', 'o', 'y', 'b'],
63
- 'population': ['s', 'n', 'a', 'v', 'y', 'c'],
64
- 'habitat': ['u', 'g', 'm', 'd', 'p', 'w', 'l']
65
- }
66
 
67
 
68
- # Convert input features dictionary to a list of dictionaries
69
- print(len(input_features))
70
  # Define the output classes
71
  output_classes = ['p', 'e']
72
 
 
2
  import pandas as pd
3
  import pickle
4
  import gradio as gr
5
+ import gradio as gr
6
+
7
  svc=pickle.load(open('svc.pickle','rb'))
8
  def predict_class(cap_shape, cap_surface, cap_color, bruises, odor, gill_attachment,
9
  gill_spacing, gill_size, gill_color, stalk_shape, stalk_root,
 
15
  stalk_surface_above_ring, stalk_surface_below_ring, stalk_color_above_ring,
16
  stalk_color_below_ring, veil_color, ring_number, ring_type, spore_print_color,
17
  population, habitat]
18
+
 
 
 
19
  features = [ 'cap-shape', 'cap-surface', 'cap-color', 'bruises', 'odor',
20
  'gill-attachment', 'gill-spacing', 'gill-size', 'gill-color',
21
  'stalk-shape', 'stalk-root', 'stalk-surface-above-ring',
22
  'stalk-surface-below-ring', 'stalk-color-above-ring',
23
  'stalk-color-below-ring', 'veil-color', 'ring-number',
24
  'ring-type', 'spore-print-color', 'population', 'habitat']
25
+ mushroom_data = {
26
+ 'cap-shape': {'bell': 'b', 'conical': 'c', 'convex': 'x', 'flat': 'f', 'knobbed': 'k', 'sunken': 's'},
27
+ 'cap-surface': {'fibrous': 'f', 'grooves': 'g', 'scaly': 'y', 'smooth': 's'},
28
+ 'cap-color': {'brown': 'n', 'buff': 'b', 'cinnamon': 'c', 'gray': 'g', 'green': 'r', 'pink': 'p', 'purple': 'u', 'red': 'e', 'white': 'w', 'yellow': 'y'},
29
+ 'bruises': {'bruises': 't', 'no': 'f'},
30
+ 'odor': {'almond': 'a', 'anise': 'l', 'creosote': 'c', 'fishy': 'y', 'foul': 'f', 'musty': 'm', 'none': 'n', 'pungent': 'p', 'spicy': 's'},
31
+ 'gill-attachment': {'attached': 'a', 'descending': 'd', 'free': 'f', 'notched': 'n'},
32
+ 'gill-spacing': {'close': 'c', 'crowded': 'w', 'distant': 'd'},
33
+ 'gill-size': {'broad': 'b', 'narrow': 'n'},
34
+ 'gill-color': {'black': 'k', 'brown': 'n', 'buff': 'b', 'chocolate': 'h', 'gray': 'g', 'green': 'r', 'orange': 'o', 'pink': 'p', 'purple': 'u', 'red': 'e', 'white': 'w', 'yellow': 'y'},
35
+ 'stalk-shape': {'enlarging': 'e', 'tapering': 't'},
36
+ 'stalk-root': {'bulbous': 'b', 'club': 'c', 'cup': 'u', 'equal': 'e', 'rhizomorphs': 'z', 'rooted': 'r', 'missing': '?'},
37
+ 'stalk-surface-above-ring': {'fibrous': 'f', 'scaly': 'y', 'silky': 'k', 'smooth': 's'},
38
+ 'stalk-surface-below-ring': {'fibrous': 'f', 'scaly': 'y', 'silky': 'k', 'smooth': 's'},
39
+ 'stalk-color-above-ring': {'brown': 'n', 'buff': 'b', 'cinnamon': 'c', 'gray': 'g', 'orange': 'o', 'pink': 'p', 'red': 'e', 'white': 'w', 'yellow': 'y'},
40
+ 'stalk-color-below-ring': {'brown': 'n', 'buff': 'b', 'cinnamon': 'c', 'gray': 'g', 'orange': 'o', 'pink': 'p', 'red': 'e', 'white': 'w', 'yellow': 'y'},
41
+ 'veil-type': {'partial': 'p', 'universal': 'u'},
42
+ 'veil-color': {'brown': 'n', 'orange': 'o', 'white': 'w', 'yellow': 'y'},
43
+ 'ring-number': {'none': 'n', 'one': 'o', 'two': 't'},
44
+ 'ring-type': {'cobwebby': 'c', 'evanescent': 'e', 'flaring': 'f', 'large': 'l', 'none': 'n', 'pendant': 'p', 'sheathing': 's', 'zone': 'z'},
45
+ 'spore-print-color': {'black': 'k', 'brown': 'n', 'buff': 'b', 'chocolate': 'h', 'green': 'r', 'orange': 'o', 'purple': 'u', 'white': 'w', 'yellow': 'y'},
46
+ 'population': {'abundant': 'a', 'clustered': 'c', 'numerous': 'n', 'scattered': 's', 'several': 'v', 'solitary': 'y'},
47
+ 'habitat': {'grasses': 'g', 'leaves': 'l', 'meadows': 'm', 'paths': 'p', 'urban': 'u', 'waste': 'w', 'woods': 'd'}
48
+ }
49
+
50
+ encoder=LabelEncoder()
51
+ real_df=pd.read_csv('mushrooms.csv')
52
+ real_df.drop(['class','veil-type'],axis=1,inplace=True)
53
+ encoded_value=[]
54
+ valueforprediction=[]
55
+ for i in range(21):
56
+ valueforprediction.append(mushroom_data[features[i]][input_data[i]])
57
+
58
+ random=pd.DataFrame([valueforprediction],columns=features)
59
  for i in real_df.columns:
60
+ print(i,real_df[i].unique())
61
  encoder.fit_transform(real_df[i])
62
  encoded_value.append(encoder.transform(random[i])[0])
63
 
 
70
 
71
 
72
 
73
+ input_features = {'cap-shape': ['bell', 'conical', 'convex', 'flat', 'knobbed', 'sunken'],
74
+ 'cap-surface': ['fibrous', 'grooves', 'scaly', 'smooth'],
75
+ 'cap-color': ['brown', 'buff', 'cinnamon', 'gray', 'green', 'pink', 'purple', 'red', 'white', 'yellow'],
76
+ 'bruises': ['bruises', 'no'],
77
+ 'odor': ['almond', 'anise', 'creosote', 'fishy', 'foul', 'musty', 'none', 'pungent', 'spicy'],
78
+ 'gill-attachment': ['attached', 'free'],
79
+ 'gill-spacing': ['close', 'crowded'],
80
+ 'gill-size': ['broad', 'narrow'],
81
+ 'gill-color': ['black', 'brown', 'buff', 'chocolate', 'gray', 'green', 'orange', 'pink', 'purple', 'red', 'white', 'yellow'],
82
+ 'stalk-shape': ['enlarging', 'tapering'],
83
+ 'stalk-root': ['bulbous', 'club', 'equal', 'rooted', 'missing'],
84
+ 'stalk-surface-above-ring': ['fibrous', 'scaly', 'silky', 'smooth'],
85
+ 'stalk-surface-below-ring': ['fibrous', 'scaly', 'silky', 'smooth'],
86
+ 'stalk-color-above-ring': ['brown', 'buff', 'cinnamon', 'gray', 'orange', 'pink', 'red', 'white', 'yellow'],
87
+ 'stalk-color-below-ring': ['brown', 'buff', 'cinnamon', 'gray', 'orange', 'pink', 'red', 'white', 'yellow'],
88
+ 'veil-color': ['brown', 'orange', 'white', 'yellow'],
89
+ 'ring-number': ['none', 'one', 'two'],
90
+ 'ring-type': [ 'evanescent', 'flaring', 'large', 'none', 'pendant'],
91
+ 'spore-print-color': ['black', 'brown', 'buff', 'chocolate', 'green', 'orange', 'purple', 'white', 'yellow'],
92
+ 'population': ['abundant', 'clustered', 'numerous', 'scattered', 'several', 'solitary'],
93
+ 'habitat': ['grasses', 'leaves', 'meadows', 'paths', 'urban', 'waste', 'woods']}
 
 
 
 
94
 
95
 
 
 
96
  # Define the output classes
97
  output_classes = ['p', 'e']
98