Mlaana commited on
Commit
ed15643
·
1 Parent(s): e8714f7

Update Interface

Browse files
Files changed (1) hide show
  1. app.py +12 -15
app.py CHANGED
@@ -20,38 +20,35 @@ def process(img):
20
  img = np.array(img) / 255.0
21
  return np.expand_dims(img, axis=0)
22
 
23
- def predict(img):
24
  img = process(img)
25
  pred = model.predict(img)
26
  class_idx = np.argmax(pred)
27
  confidence = pred[0][class_idx]
28
  class_name = class_labels[class_idx]
29
- if confidence < CONFIDENCE_THRESHOLD :
 
30
  return {
31
- 'label' : 'Tidak Dikenali',
32
- 'confidence' : float(confidence),
33
- 'status' : 'Unknown',
34
  }
35
  else:
36
- return {
37
- 'label' : class_name,
38
- 'confidence' : float(confidence),
39
- 'status' : 'Ok'
40
  }
41
 
42
 
 
43
  interface = gr.Interface(
44
  fn=predict,
45
  inputs=[
46
  gr.Image(type="pil"),
47
  gr.Slider(0, 1, value=0.5, label="Confidence Threshold")
48
  ],
49
- outputs=[
50
- gr.Textbox(label="Label"),
51
- gr.Textbox(label="Confidence"),
52
- gr.Textbox(label="Status")
53
- ],
54
- title="CNN Makanan Classifier"
55
  )
56
 
57
  interface.launch()
 
20
  img = np.array(img) / 255.0
21
  return np.expand_dims(img, axis=0)
22
 
23
+ def predict(img, threshold):
24
  img = process(img)
25
  pred = model.predict(img)
26
  class_idx = np.argmax(pred)
27
  confidence = pred[0][class_idx]
28
  class_name = class_labels[class_idx]
29
+
30
+ if confidence < threshold:
31
  return {
32
+ "label": "Tidak Dikenali",
33
+ "confidence": float(confidence),
34
+ "status": "Unknown"
35
  }
36
  else:
37
+ return {
38
+ "label": class_name,
39
+ "confidence": float(confidence),
40
+ "status": "OK"
41
  }
42
 
43
 
44
+
45
  interface = gr.Interface(
46
  fn=predict,
47
  inputs=[
48
  gr.Image(type="pil"),
49
  gr.Slider(0, 1, value=0.5, label="Confidence Threshold")
50
  ],
51
+ outputs=gr.JSON(label="Hasil Prediksi")
 
 
 
 
 
52
  )
53
 
54
  interface.launch()