nuckingfutz commited on
Commit
f440262
1 Parent(s): 3aea5f2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pickle
2
+ import numpy as np
3
+ import pandas as pd
4
+ from PIL import Image, ImageOps
5
+
6
+ model = pickle.load(open("catboost.pkl", "rb"))
7
+
8
+ def classify_image(image):
9
+ image = Image.fromarray(image)
10
+ labels = ['Brain Tumor Present', 'No Brain Tumor']
11
+ image = image.resize((120, 120))
12
+ image = ImageOps.grayscale(image)
13
+ image = np.array(image).reshape((1, -1))
14
+ res = {labels[0]:float(model.predict_proba(image)[0][1]), labels[1]: float(model.predict_proba(image)[0][0])}
15
+ if model.predict_proba(image)[0][0] < 0.5:
16
+ pred = "The MRI image contains a Brain Tumor"
17
+ symptoms = "Possible Symptoms : New or increasingly strong headaches, blurred vision, loss of balance, confusion and seizures (In some cases, there may be no symptoms as well)"
18
+
19
+ else:
20
+ pred = "The MRI image does not have a Brain Tumor"
21
+ symptoms = "Possible Symptoms : None"
22
+ return pred, res, symptoms
23
+
24
+
25
+ label1 = gr.outputs.Label(label="Prediction")
26
+ label2 = gr.outputs.Label(label="Confidence Score")
27
+ label3 = gr.outputs.Label(label="Symptoms")
28
+ image = gr.inputs.Image()
29
+
30
+ interface = gr.Interface(title = "Brain Tumor Classifier",
31
+ description="This an Online tool representing AI for a good cause, this online AI powered web application is built by Rauhan Ahmed Siddiqui, using this tool, one could know whether his/her brain MRI report contains a tumor or not with great accuracy, no matter how difficult it is to see that from a human eye.",
32
+ fn=classify_image,
33
+ inputs=image,
34
+ outputs=[label1, label2, label3],
35
+ examples=[["1 no.jpeg"],["3 no.jpeg"],["Y4.jpeg"],["Y6.jpeg"]],
36
+ interpretation=None,
37
+ layout="unaligned",
38
+ theme='dark-grass')
39
+
40
+ interface.launch()