Spaces:
Build error
Build error
Upload 6 files
Browse files"initial"
- .gitignore +2 -0
- app.py +21 -0
- predict.py +26 -0
- requirements.txt +0 -0
.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
venv
|
| 2 |
+
model
|
app.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from predict import makepredictions
|
| 3 |
+
|
| 4 |
+
with gr.Blocks() as demo:
|
| 5 |
+
gr.Markdown("Brain Tumor Image classification")
|
| 6 |
+
gr.Markdown("We detect 4 Types of Tumor with 99.12% Accuracy:")
|
| 7 |
+
gr.Markdown("Glioma | Meningioma | No Tumor | Pituitary")
|
| 8 |
+
image_input = gr.Image(label='Tumor Image', type='filepath', height=480)
|
| 9 |
+
with gr.Row():
|
| 10 |
+
image_button = gr.Button("Predict")
|
| 11 |
+
y_pred = output = gr.Textbox(label="Tumor Type:")
|
| 12 |
+
image_button.click(makepredictions, inputs=image_input, outputs=y_pred)
|
| 13 |
+
gr.Markdown(
|
| 14 |
+
"""
|
| 15 |
+
This model is trained on the Kaggle dataset:
|
| 16 |
+
- Only for the educational purpose
|
| 17 |
+
- Play with that and Have fun.
|
| 18 |
+
""")
|
| 19 |
+
|
| 20 |
+
if __name__ == "__main__":
|
| 21 |
+
demo.launch()
|
predict.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
import tf_keras
|
| 3 |
+
model_mri = tf_keras.models.load_model('model')
|
| 4 |
+
|
| 5 |
+
def load_image_with_path(path):
|
| 6 |
+
img = tf.io.read_file(path)
|
| 7 |
+
img = tf.image.decode_image(img, channels=3)
|
| 8 |
+
img = tf.image.resize(img, size=[256, 256])
|
| 9 |
+
img = img / 255.
|
| 10 |
+
return img
|
| 11 |
+
|
| 12 |
+
def makepredictions(path):
|
| 13 |
+
print(path)
|
| 14 |
+
img = load_image_with_path(path)
|
| 15 |
+
predictions = model_mri.predict(tf.expand_dims(img, axis=0))
|
| 16 |
+
a = int(tf.argmax(tf.squeeze(predictions)))
|
| 17 |
+
if a == 0:
|
| 18 |
+
a = "Result : Glioma Tumor"
|
| 19 |
+
elif a == 1:
|
| 20 |
+
a = "Result : Meningioma Tumor"
|
| 21 |
+
elif a == 2:
|
| 22 |
+
a = "Result : No Tumor"
|
| 23 |
+
else:
|
| 24 |
+
a = "Result : Pituitary Tumor"
|
| 25 |
+
return a
|
| 26 |
+
# {'glioma': 0, 'meningioma': 1, 'notumor': 2, 'pituitary': 3}
|
requirements.txt
ADDED
|
Binary file (3.28 kB). View file
|
|
|