AmimulBmeIU commited on
Commit
bbf3a3c
·
verified ·
1 Parent(s): ca0d971

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ CLASS_NAMES = [
7
+ "MildDemented",
8
+ "Moderate Dementia",
9
+ "NonDemented",
10
+ "Very mild Dementia",
11
+ "glioma",
12
+ "meningioma",
13
+ "notumor",
14
+ "pituitary"
15
+ ]
16
+
17
+ # Load model locally in the Space
18
+ model = tf.keras.models.load_model("alz_classifier.keras")
19
+
20
+ def predict_mri(img):
21
+ img = img.resize((128,128))
22
+ x = np.array(img)/255.0
23
+ x = np.expand_dims(x, axis=0)
24
+
25
+ preds = model.predict(x)
26
+ pred_class = CLASS_NAMES[np.argmax(preds)]
27
+ return {pred_class: float(np.max(preds))}
28
+
29
+ demo = gr.Interface(
30
+ fn=predict_mri,
31
+ inputs=gr.Image(type="pil"),
32
+ outputs=gr.Label(num_top_classes=1),
33
+ title="Alzheimer & Brain Tumor 8-Class MRI Classifier",
34
+ description="Upload an MRI image to classify into 8 classes."
35
+ )
36
+
37
+ demo.launch()