import gradio as gr import tensorflow as tf import tensorflow.keras import matplotlib.pyplot as plt import cv2 import tensorflow_io as tfio import numpy as np loaded_model = tf.keras.models.load_model( 'kidney2.h5') def take_img(img): resize = tf.image.resize(img, (224,224)) gray = tfio.experimental.color.bgr_to_rgb(resize) yhat = loaded_model.predict(np.expand_dims(gray/255, 0)) label_names = { "1": "Cyst", "2": "Normal", "3": "Stone", "4": "Tumor" } classes_x=np.argmax(yhat,axis=1) a = classes_x[0] input_value = a + 1 input_str = str(input_value) predicted_label = label_names[input_str] q= yhat[0][0] w = yhat[0][1] e = yhat[0][2] r = yhat[0][3] q = str(q) w = str(w) e = str(e) r = str(r) return {'cryst' : q ,'Normal' : w ,'Stone' : e ,'Tumour' : r } image = gr.inputs.Image(shape=(224,224)) label = gr.outputs.Label('ok') gr.Interface(fn=take_img, inputs=image, outputs="label",interpretation='default').launch(debug='True')