Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -12,18 +12,22 @@ model = load_model('daging128.model')
|
|
12 |
mlb = pickle.loads(open('daging128.pickle', "rb").read())
|
13 |
labl = ['Busuk', 'Segar', 'Setengah']
|
14 |
def gambaran(image):
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
25 |
|
26 |
|
27 |
|
28 |
-
demo = gr.Interface(gambaran, gr.Image(), "
|
29 |
demo.launch()
|
|
|
12 |
mlb = pickle.loads(open('daging128.pickle', "rb").read())
|
13 |
labl = ['Busuk', 'Segar', 'Setengah']
|
14 |
def gambaran(image):
|
15 |
+
output = imutils.resize(image, width=400)
|
16 |
+
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
17 |
+
image = cv2.resize(image, (128, 128))
|
18 |
+
image = image.astype("float") / 255.0
|
19 |
+
image = img_to_array(image)
|
20 |
+
image = np.expand_dims(image, axis=0)
|
21 |
+
proba = model.predict(image)[0]
|
22 |
+
idxs = np.argsort(proba)[::-1][:2]
|
23 |
+
print(labl[idxs[0]])
|
24 |
+
for (i, j) in enumerate(idxs):
|
25 |
+
label = "{}: {:.2f}%".format(mlb.classes_[j], proba[j] * 100)
|
26 |
+
cv2.putText(output, label, (10, (i * 30) + 25),
|
27 |
+
cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2)
|
28 |
+
return output
|
29 |
|
30 |
|
31 |
|
32 |
+
demo = gr.Interface(gambaran, gr.Image(), "image")
|
33 |
demo.launch()
|