|
import gradio as gr |
|
import tensorflow |
|
import numpy |
|
from tensorflow.keras.preprocessing import image |
|
from tensorflow.keras.models import load_model |
|
|
|
model = load_model('vgg_model.keras') |
|
|
|
def predict(img): |
|
img = image.img_to_array(img) |
|
img = numpy.expand_dims(img, axis=0) |
|
img = img.reshape((-1, 150, 150, 3)) |
|
prediction = model.predict(img) |
|
confidences = {"Cat": float(prediction[0]), 'Dog': float(prediction[1])} |
|
return confidences |
|
|
|
|
|
demo = gr.Interface( |
|
fn=predict, |
|
inputs=gr.Image(shape=(150, 150)), |
|
outputs=gr.Label(num_top_classes=2), |
|
) |
|
|
|
|
|
demo.launch() |