Pizza_Steak / app.py
Sandhya
First Commit
a7905c1
raw
history blame contribute delete
923 Bytes
import gradio as gr
import tensorflow as tf
import numpy as np
from timeit import default_timer as timer
import matplotlib.pyplot as plt
from PIL import Image
model=tf.keras.models.load_model("pizza_steak.keras")
class_names=['Pizza','Steak']
def load_and_prep_image(img,img_shape=224):
if isinstance(img,Image.Image):
img=np.array(img)
img=tf.convert_to_tensor(img,dtype=tf.float32)
img=tf.image.resize(img,size=[img_shape,img_shape])
img=img/255
return img
def predict(img):
start_time=timer()
img=load_and_prep_image(img)
pred=model.predict(tf.expand_dims(img,axis=0))
pred_class=class_names[int(tf.round(pred)[0][0])]
pred_time=round(timer()-start_time,5)
return pred_class,pred_time
demo=gr.Interface(fn=predict,inputs=gr.Image(type="pil"),outputs=[gr.Label(num_top_classes=2),gr.Number(label="Prediction time")],title="Pizza vs Steak Classification")
demo.launch()