File size: 1,108 Bytes
10bb510
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4d84e99
 
 
 
 
 
10bb510
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
38
39
40
41
42
43
44
45
46
47
import gradio as gr
import tensorflow as tf

def classify_image(Image):
    model = tf.keras.models.load_model('tumor_model.h5')
    labels = [
        'Tumor - Glioma', 
        'No Tumor', 
        'Tumor - Meningioma', 
        'Tumor - Pituitary'
    ]
    
    inp = Image.reshape((-1, 128, 128, 3))
    inp = tf.keras.applications.resnet50.preprocess_input(inp)
    prediction = model.predict(inp).flatten()
    confidences = {labels[i]: float(prediction[i]) for i in range(4)}
    
    return confidences

image_input = gr.inputs.Image(shape = (128, 128))
label_output = gr.outputs.Label(num_top_classes = 4)

title = "Tumor Classification"
description = "Upload an image and get predictions for tumor classification."
examples = [
    ['Example 1.jpg'],
    ['Example 2.jpg']
]

interface = gr.Interface(
    fn = classify_image,
    inputs = image_input,
    outputs = label_output,
    title = title,
    description = description,
    examples = examples,
    button_style ='danger',
    theme = 'huggingface'
)

interface.css = """
    .main {
        margin: 0 10%;
    }
"""

interface.launch()