rishabh5752 commited on
Commit
164e569
·
1 Parent(s): 03082bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -24,16 +24,17 @@ def predict(image):
24
 
25
  return {'label': label, 'confidence': float(confidence)} # Convert confidence to float
26
 
27
- # Custom post-processing function to sort by confidence
28
  def custom_postprocess(output):
29
- sorted_output = sorted(output.items(), key=lambda x: x[1], reverse=True)
30
- return f"{sorted_output[0][0]} ({sorted_output[0][1] * 100:.2f}%)"
 
31
 
32
  examples = [["benign.jpg"], ["malignant.jpg"]]
33
 
34
  # Define input and output components
35
  image_input = gr.inputs.Image(shape=(150, 150))
36
- label_output = gr.outputs.Label(postprocess=custom_postprocess)
37
 
38
  # Define a Gradio interface for user interaction
39
  iface = gr.Interface(
 
24
 
25
  return {'label': label, 'confidence': float(confidence)} # Convert confidence to float
26
 
27
+ # Custom post-processing function to format the label and confidence
28
  def custom_postprocess(output):
29
+ label = output['label']
30
+ confidence = output['confidence'] * 100
31
+ return f"{label} ({confidence:.2f}%)"
32
 
33
  examples = [["benign.jpg"], ["malignant.jpg"]]
34
 
35
  # Define input and output components
36
  image_input = gr.inputs.Image(shape=(150, 150))
37
+ label_output = gr.outputs.Label()
38
 
39
  # Define a Gradio interface for user interaction
40
  iface = gr.Interface(