Spaces:
Runtime error
Runtime error
Asadel Ann commited on
Commit ·
4dd14c0
1
Parent(s): 1a51889
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from tensorflow.keras.models import load_model
|
| 4 |
+
import imutils
|
| 5 |
+
import matplotlib.pyplot as plt
|
| 6 |
+
import cv2
|
| 7 |
+
import numpy as np
|
| 8 |
+
from tensorflow.keras.preprocessing.image import img_to_array
|
| 9 |
+
|
| 10 |
+
model = load_model('/content/bananafreshness/pisang.h5')
|
| 11 |
+
def prosesgambar(gambar):
|
| 12 |
+
# load the image
|
| 13 |
+
image = gambar
|
| 14 |
+
output = imutils.resize(image, width=400)
|
| 15 |
+
|
| 16 |
+
# pre-process the image for classification
|
| 17 |
+
image = cv2.resize(image, (94, 94))
|
| 18 |
+
image = image.astype("float") / 255.0
|
| 19 |
+
image = img_to_array(image)
|
| 20 |
+
image = np.expand_dims(image, axis=0)
|
| 21 |
+
return image
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def prediksi(gambar):
|
| 27 |
+
a = np.round(model.predict(prosesgambar(gambar)), 4)[0].tolist()
|
| 28 |
+
if a.index(max(a)) == 1:
|
| 29 |
+
pred = "Segar"
|
| 30 |
+
else:
|
| 31 |
+
pred = "Busuk"
|
| 32 |
+
return pred
|
| 33 |
+
|
| 34 |
+
demo = gr.Interface(prediksi, gr.Image(shape=(200, 200)), "text")
|
| 35 |
+
demo.launch()
|