File size: 934 Bytes
7d93a92
cab105c
7d93a92
 
 
cab105c
 
5a2dc7d
 
 
 
 
 
 
cab105c
 
 
5a2dc7d
 
 
 
 
 
cab105c
 
 
 
 
 
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
import gradio as gr
import tensorflow as tf
import tensorflow_io as tfio
import numpy as np

loaded_model = tf.keras.models.load_model('kidney2.h5')

label_names = {
    "1": "Cyst",
    "2": "Normal",
    "3": "Stone",
    "4": "Tumor"
}

def classify_kidney_image(img):
    resize = tf.image.resize(img, (224, 224))
    gray = tfio.experimental.color.bgr_to_rgb(resize)
    normalized_img = gray / 255.0
    yhat = loaded_model.predict(np.expand_dims(normalized_img, 0))
    class_index = np.argmax(yhat, axis=1)[0]
    predicted_label = label_names[str(class_index + 1)]
    probabilities = {label_names[str(i + 1)]: str(prob) for i, prob in enumerate(yhat[0])}
    return predicted_label, probabilities

image = gr.inputs.Image(shape=(224, 224))
label = gr.outputs.Label()

app = gr.Interface(fn=classify_kidney_image, inputs=image, outputs=label, interpretation='default', title='Kidney Image Classifier')
app.launch(debug=True)