asaderu commited on
Commit
e65597a
·
1 Parent(s): d260c54

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -11
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
- image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
16
- image = cv2.resize(image, (128, 128))
17
- image = image.astype("float") / 255.0
18
- image = img_to_array(image)
19
- image = np.expand_dims(image, axis=0)
20
-
21
-
22
- proba = model.predict(image)[0]
23
- idxs = np.argsort(proba)[::-1][:2]
24
- return labl[idxs[0]]
 
 
 
 
25
 
26
 
27
 
28
- demo = gr.Interface(gambaran, gr.Image(), "text")
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()