import gradio as gr import tensorflow as tf import numpy as np num_classes = 200 IMG_HEIGHT = 256 IMG_WIDTH = 256 with open("classlabel.txt", 'r') as file: CLASS_LABEL = [x.strip() for x in file.readlines()] def normalize_image(img): img = tf.cast(img, tf.float32)/255. img = tf.image.resize(img, (IMG_HEIGHT, IMG_WIDTH), method='bilinear') return img def predict_fn(img): img = img.convert('RGB') img_data = normalize_image(img) x = np.array(img_data) x = np.expand_dims(x, axis=0) temp = model.predict(x) class_index = np.argmax(temp) return CLASS_LABEL[class_index] model = tf.keras.models.load_model("model019.h5") interface = gr.Interface(predict_fn, gr.inputs.Image(type='pil'), outputs='label') interface.launch()