File size: 816 Bytes
6d162c2
 
 
 
 
 
 
 
 
8dd048d
 
 
6d162c2
 
 
 
 
bb7be60
6d162c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import tensorflow as tf
import numpy as np

# Load the model
model = tf.keras.models.load_model('model.h5')

# Define the class names
class_names = {
    0: 'Glioma',
    1: 'Menin',
    2: 'Tumor'
}


def classify_image(image):
    # Preprocess the image
    img_array = tf.image.resize(image, [200, 200])
    img_array = tf.expand_dims(img_array, 0) / 255.0

    # Make a prediction
    prediction = model.predict(img_array)
    predicted_class = tf.argmax(prediction[0], axis=-1)
    confidence = np.max(prediction[0])

    return class_names[predicted_class.numpy()], confidence


iface = gr.Interface(
    fn=classify_image,
    inputs="image",
    outputs=["text", "number"],
    examples=[
        ['examples/0.jpg'],
        ['examples/1.jpg'],
	['examples/2.jpg'],
    ])
iface.launch()