File size: 1,313 Bytes
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
from tensorflow.keras.models import load_model
print("[INFO] loading network...")
model = load_model('daging128.model')
mlb = pickle.loads(open('daging128.pickle', "rb").read())

labels = ['Busuk', 'Segar', 'Setengah']

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 gambaran(image):
    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]
    return labels[idxs[0]]


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(gambaran, gr.Image(shape=(128, 128)), "text")
demo.launch()