Spaces:
Runtime error
Runtime error
File size: 822 Bytes
fa9ffa5 c22b0bb fa9ffa5 c22b0bb fa9ffa5 c22b0bb fa9ffa5 c22b0bb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import gradio as gr
from fastai.vision.all import *
learn = load_learner("brain_tumor_prediction_model.pkl")
categories = ("No tumor detected", "A tumor was detected")
def classify_image(img):
"""
Classify an brain mri as a tumor or not a tumor
Parameters
----------
img : PIL image
The image to classify
Returns
-------
dict
A dictionary with the class names as keys and the probabilities as values
"""
pred, pred_idx, probs = learn.predict(img)
print(probs)
return {categories[i]: float(probs[i]) for i in range(2)}
image = gr.inputs.Image(shape=(224, 224))
label = gr.outputs.Label()
examples = ["normal_brain_mri.jpeg", "images2.jpeg"]
gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples).launch(
inline=False
)
|