Viraj2307's picture
Initial Commit
af9965e verified
import gradio as gr
import numpy as np
from tensorflow.keras.models import load_model
from PIL import Image
model = load_model("final/brain_tumor_fine_tune.h5")
model.load_weights("final/brain_tumor_fine_tune.h5")
class_names = [
'glioma',
'meningioma',
'notumor',
'pituitary',
]
def classify_tumor(input_image):
img = Image.fromarray(input_image)
resized_img = img.resize((299, 299))
img = np.asarray(resized_img)
img = np.expand_dims(img, axis=0)
img = img / 255
prediction = model.predict(img)
confidences = {class_names[i]: float(prediction[0][i]) for i in range(len(class_names))}
return {class_name: conf for class_name, conf in sorted(confidences.items(), key=lambda x: x[1], reverse=True)}
iface = gr.Interface(
fn=classify_tumor,
inputs=gr.Image(type="numpy"),
outputs=gr.Label(num_top_classes=5),
title="Brain Tumor Classification",
description="Upload an image of a Brain to classify its tumor.",
theme=gr.themes.Soft()
)
# Launch the interface
iface.launch(share=True)