asaderu's picture
Create app.py
4dd14c0
raw
history blame
860 Bytes
import numpy as np
import gradio as gr
from tensorflow.keras.models import load_model
import imutils
import matplotlib.pyplot as plt
import cv2
import numpy as np
from tensorflow.keras.preprocessing.image import img_to_array
model = load_model('/content/bananafreshness/pisang.h5')
def prosesgambar(gambar):
# load the image
image = gambar
output = imutils.resize(image, width=400)
# pre-process the image for classification
image = cv2.resize(image, (94, 94))
image = image.astype("float") / 255.0
image = img_to_array(image)
image = np.expand_dims(image, axis=0)
return image
def prediksi(gambar):
a = np.round(model.predict(prosesgambar(gambar)), 4)[0].tolist()
if a.index(max(a)) == 1:
pred = "Segar"
else:
pred = "Busuk"
return pred
demo = gr.Interface(prediksi, gr.Image(shape=(200, 200)), "text")
demo.launch()