Mthd98/Image_Classifier
0
1import tensorflow as tf2import numpy as np 3import requests4import gradio as gr5 6model = tf.keras.applications.DenseNet121(input_shape=(224, 224, 3))7 8response=requests.get('https://raw.githubusercontent.com/gradio-app/mobilenet-example/master/labels.txt')9labels=response.text.split('\n')10 11 12def make_pred(image):13 image=tf.image.resize(image,(224,224))14 image=tf.keras.applications.densenet.preprocess_input(image)15 image=tf.expand_dims(image,0)16 pred = model.predict(image).reshape(-1)17 18 conf= {}19 for i in range(len(labels[:-1])):20 conf[labels[i]]=float(pred[i])21 22 23 24 return conf25 26demo = gr.Interface(fn=make_pred,inputs=[gr.inputs.Image()],27 outputs=[gr.outputs.Label(num_top_classes=5)])28demo.launch()