import gradio as gr import tensorflow as tf import numpy as np from PIL import Image new_model = tf.keras.models.load_model("./MobileNet-V2-Cats-Dogs.keras") def image_classifier(inp): # Convert PIL image to TensorFlow tensor img = tf.convert_to_tensor(inp, dtype=tf.float32) # Resize the image img = tf.image.resize(img, (160,160)) out = new_model.predict(tf.expand_dims(img,0)).flatten() predictions = tf.where(out < 0.5, 0, 1) predictions = tf.squeeze(predictions) print("The out : ", out[0]) if out[0] > 0.5 : return {'dog': 1} else: return {'cat': 1} demo = gr.Interface(fn=image_classifier, inputs="image", outputs="label") demo.launch(debug=True)