abdabbas commited on
Commit
8ff5a8d
1 Parent(s): eee6e84
Files changed (1) hide show
  1. app.py +50 -50
app.py CHANGED
@@ -1,51 +1,51 @@
1
- import gradio as gr
2
- import numpy as np
3
- from skimage.transform import resize
4
- from tensorflow.keras.models import Sequential, load_model
5
- from tensorflow.keras.layers import Conv2D, MaxPool2D, Dropout, Dense, Flatten, BatchNormalization
6
-
7
- class SkinCancer :
8
- def __init__ (self):
9
- self.model = self.load_model()
10
-
11
- def build_model (self) :
12
- model = Sequential()
13
- model.add(Conv2D(filters = 128, kernel_size = (4,4), input_shape = (32, 32, 3), activation = 'relu'))
14
- model.add(MaxPool2D(pool_size = (4,4)))
15
- model.add(Conv2D(filters = 64, kernel_size = (2,2), activation = 'relu'))
16
- model.add(MaxPool2D(pool_size = (2,2)))
17
- model.add(BatchNormalization())
18
- #model.add(GlobalAveragePooling2D())
19
- model.add(Flatten())
20
- model.add(Dense(128, activation = 'relu'))
21
- model.add(Dropout(0.2))
22
- model.add(Dense(2, activation = 'sigmoid')) # sigmoid is better for binary classification
23
- #model.summary()
24
- return model
25
-
26
- def load_model(self):
27
- model = self.build_model()
28
- model = load_model("Normal_skin_cancer_model.h5")
29
- return model
30
-
31
- def preprocess_image(self,img):
32
- img = resize(img, (32,32))
33
- img = img.reshape(1,32,32,3)
34
- return img
35
-
36
- def predict(self,img):
37
- real_labels = ["benign", "malignant"]
38
- img = self.preprocess_image(img)
39
- res = np.argmax(self.model.predict(img))
40
- return real_labels[res]
41
-
42
- def Test(img):
43
- model_new = SkinCancer()
44
- res = model_new.predict(img)
45
- return res
46
- #interface
47
- interface = gr.Interface(fn = Test,
48
- inputs = gr.inputs.Image(shape=(200,200)),
49
- outputs=["text"],
50
- title="Skin Cancer detection")
51
  interface.launch()
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from skimage.transform import resize
4
+ from tensorflow.keras.models import Sequential, load_model
5
+ from tensorflow.keras.layers import Conv2D, MaxPool2D, Dropout, Dense, Flatten, BatchNormalization
6
+
7
+ class SkinCancer :
8
+ def __init__ (self):
9
+ self.model = self.load_model()
10
+
11
+ def build_model (self) :
12
+ model = Sequential()
13
+ model.add(Conv2D(filters = 128, kernel_size = (4,4), input_shape = (32, 32, 3), activation = 'relu'))
14
+ model.add(MaxPool2D(pool_size = (4,4)))
15
+ model.add(Conv2D(filters = 64, kernel_size = (2,2), activation = 'relu'))
16
+ model.add(MaxPool2D(pool_size = (2,2)))
17
+ model.add(BatchNormalization())
18
+ #model.add(GlobalAveragePooling2D())
19
+ model.add(Flatten())
20
+ model.add(Dense(128, activation = 'relu'))
21
+ model.add(Dropout(0.2))
22
+ model.add(Dense(1, activation = 'sigmoid')) # sigmoid is better for binary classification
23
+ #model.summary()
24
+ return model
25
+
26
+ def load_model(self):
27
+ model = self.build_model()
28
+ model = load_model("Normal_skin_cancer_model.h5")
29
+ return model
30
+
31
+ def preprocess_image(self,img):
32
+ img = resize(img, (32,32))
33
+ img = img.reshape(1,32,32,3)
34
+ return img
35
+
36
+ def predict(self,img):
37
+ real_labels = ["benign", "malignant"]
38
+ img = self.preprocess_image(img)
39
+ res = np.argmax(self.model.predict(img))
40
+ return real_labels[res]
41
+
42
+ def Test(img):
43
+ model_new = SkinCancer()
44
+ res = model_new.predict(img)
45
+ return res
46
+ #interface
47
+ interface = gr.Interface(fn = Test,
48
+ inputs = gr.inputs.Image(shape=(200,200)),
49
+ outputs=["text"],
50
+ title="Skin Cancer detection")
51
  interface.launch()