File size: 895 Bytes
9979851
 
 
 
 
357e4b2
9979851
 
 
357e4b2
9979851
 
357e4b2
82380de
da28b1b
82380de
357e4b2
82380de
9979851
 
 
82380de
9979851
 
82380de
c2d1e0b
 
82380de
 
9979851
 
 
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
import gradio as gr
import tensorflow as tf
from PIL import Image
import numpy as np

# Laden des Modells
model_path = "brain_classification.keras"
model = tf.keras.models.load_model(model_path)

# Klassenlabels
labels = ['glioma_tumor', 'meningioma_tumor', 'no_tumor', 'pituitary_tumor']

def predict_image(image):
    image = Image.fromarray(image.astype('uint8'), 'RGB')
    image = image.resize((224, 224)) 
    image = np.array(image)

    prediction = model.predict(np.expand_dims(image, axis=0))
    confidences = {labels[i]: float(prediction[0][i]) for i in range(len(labels))}
    return confidences

# Gradio interface
iface = gr.Interface(
    fn=predict_image,
    inputs=gr.Image(),
    outputs=gr.Label(num_top_classes=4),
    title="MRI Tumor Classifier",
    description="Upload your MRI image and the model will predict, if there's a tumor present"

)

iface.launch(share=True)