asaderu commited on
Commit
ce46431
1 Parent(s): 152c8e8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ from tensorflow.keras.models import load_model
10
+ print("[INFO] loading network...")
11
+ model = load_model('daging128.model')
12
+ mlb = pickle.loads(open('daging128.pickle', "rb").read())
13
+
14
+ labels = ['Busuk', 'Segar', 'Setengah']
15
+
16
+ def prosesgambar(gambar):
17
+ # load the image
18
+ image = gambar
19
+ output = imutils.resize(image, width=400)
20
+
21
+ # pre-process the image for classification
22
+ image = cv2.resize(image, (94, 94))
23
+ image = image.astype("float") / 255.0
24
+ image = img_to_array(image)
25
+ image = np.expand_dims(image, axis=0)
26
+ return image
27
+
28
+
29
+ def gambaran(image):
30
+ image = cv2.resize(image, (128, 128))
31
+ image = image.astype("float") / 255.0
32
+ image = img_to_array(image)
33
+ image = np.expand_dims(image, axis=0)
34
+
35
+
36
+ proba = model.predict(image)[0]
37
+ idxs = np.argsort(proba)[::-1][:2]
38
+ return labels[idxs[0]]
39
+
40
+
41
+ def prediksi(gambar):
42
+ a = np.round(model.predict(prosesgambar(gambar)), 4)[0].tolist()
43
+ if a.index(max(a)) == 1:
44
+ pred = "Segar"
45
+ else:
46
+ pred = "Busuk"
47
+ return pred
48
+
49
+ demo = gr.Interface(gambaran, gr.Image(shape=(128, 128)), "text")
50
+ demo.launch()