import tensorflow as tf import numpy as np import requests import gradio as gr model = tf.keras.applications.DenseNet121(input_shape=(224, 224, 3)) response=requests.get('https://raw.githubusercontent.com/gradio-app/mobilenet-example/master/labels.txt') labels=response.text.split('\n') def make_pred(image): image=tf.image.resize(image,(224,224)) image=tf.keras.applications.densenet.preprocess_input(image) image=tf.expand_dims(image,0) pred = model.predict(image).reshape(-1) conf= {} for i in range(len(labels[:-1])): conf[labels[i]]=float(pred[i]) return conf demo = gr.Interface(fn=make_pred,inputs=[gr.inputs.Image()], outputs=[gr.outputs.Label(num_top_classes=5)]) demo.launch()