fohy24 commited on
Commit
30a5c0f
·
1 Parent(s): 7d51cfd

added slider to control prediction confidence

Browse files
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -28,7 +28,7 @@ labels = ['Pastel',
28
  'Super Pastel']
29
  num_labels = len(labels)
30
 
31
- def predict(img):
32
 
33
  new_layers = nn.Sequential(
34
  nn.Linear(1920, 1000), # Reduce dimension from 1024 to 500
@@ -66,14 +66,15 @@ def predict(img):
66
  output = densenet(input_img)
67
 
68
  predicted_probs = torch.sigmoid(output).to('cpu').flatten().tolist()
69
- prediction_dict = {labels[i]: predicted_probs[i] for i in range(len(labels)) if predicted_probs[i] > 0.5}
70
 
71
  return prediction_dict
72
 
73
  import gradio as gr
74
 
75
  gr.Interface(fn=predict,
76
- inputs=gr.Image(type="pil"),
 
77
  outputs=gr.Label(),
78
  examples=["pastel_yb.png", "piebald.png", "leopard_fire.png"],
79
  title='Ball Python Morph Identifier',
 
28
  'Super Pastel']
29
  num_labels = len(labels)
30
 
31
+ def predict(img, confidence):
32
 
33
  new_layers = nn.Sequential(
34
  nn.Linear(1920, 1000), # Reduce dimension from 1024 to 500
 
66
  output = densenet(input_img)
67
 
68
  predicted_probs = torch.sigmoid(output).to('cpu').flatten().tolist()
69
+ prediction_dict = {labels[i]: predicted_probs[i] for i in range(len(labels)) if predicted_probs[i] > confidence}
70
 
71
  return prediction_dict
72
 
73
  import gradio as gr
74
 
75
  gr.Interface(fn=predict,
76
+ inputs=[gr.Image(type="pil"),
77
+ gr.Slider(0, 1, value=0.5, label="Confidence", info="Show predictions that are above this confidence level")],
78
  outputs=gr.Label(),
79
  examples=["pastel_yb.png", "piebald.png", "leopard_fire.png"],
80
  title='Ball Python Morph Identifier',