File size: 1,020 Bytes
ce46431
 
 
 
 
 
 
 
ad20374
 
ce46431
 
950b73e
ce46431
95b05a9
e65597a
 
 
 
 
 
 
 
 
 
 
 
581e1b5
ce46431
 
 
54bea6e
ce46431
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import numpy as np
import gradio as gr
import imutils
import matplotlib.pyplot as plt
import cv2
import numpy as np
from tensorflow.keras.preprocessing.image import img_to_array
from tensorflow.keras.models import load_model
import pickle

model = load_model('daging128.model')
mlb = pickle.loads(open('daging128.pickle', "rb").read())
labl = ['Busuk', 'Segar', 'Setengah']
def gambaran(image):
  output = imutils.resize(image, width=400)
  image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
  image = cv2.resize(image, (128, 128))
  image = image.astype("float") / 255.0
  image = img_to_array(image)
  image = np.expand_dims(image, axis=0)
  proba = model.predict(image)[0]
  idxs = np.argsort(proba)[::-1][:2]
  print(labl[idxs[0]])
  for (i, j) in enumerate(idxs):
    label = "{}: {:.2f}%".format(mlb.classes_[j], proba[j] * 100)
    cv2.putText(output, label, (10, (i * 30) + 25), 
      cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2)
  return output



demo = gr.Interface(gambaran, gr.Image(), "image")
demo.launch()