Spaces:
Build error
Build error
import numpy as np | |
import tensorflow as tf | |
from tensorflow import keras | |
from PIL import Image | |
import numpy as np | |
from skimage import transform | |
import numpy as np | |
import tensorflow as tf | |
from tensorflow import keras | |
import gradio as gr | |
savedModel = keras.models.load_model("my_h5_model.h5") | |
def predict(image): | |
classes=['fresh apple','fresh banana','fresh orange','rotten apple','rotten banana','rotten orange'] | |
np_image = np.array(image).astype('float32')/255 | |
np_image = transform.resize(np_image, (300, 300, 3)) | |
np_image = np.expand_dims(np_image, axis=0) | |
softmax=savedModel.predict(np_image).flatten().tolist() | |
confidence = dict(zip(classes, softmax)) | |
return confidence | |
print("this model is trained on 3 fruits only.Apples, Oranges, and Bananas") | |
gr.Interface(fn=predict, | |
inputs="image", | |
outputs=gr.Label(num_top_classes=3), | |
examples=['apple.jpg','orange.jpg','banana.jpg']).launch() | |