Frantz103 commited on
Commit
32d6eef
1 Parent(s): 161ceef

Update app.py

Browse files

UX updated, added confidence labels for the output components

Files changed (1) hide show
  1. app.py +4 -2
app.py CHANGED
@@ -21,6 +21,8 @@ def predict(image):
21
  # Apply the threshold
22
  threshold = 0.570
23
  classes_with_probs = [(learn.dls.vocab[i], probs[i].item()) for i in range(len(mask)) if probs[i] > threshold]
 
 
24
 
25
  # Check if the prediction includes "dog" or "cat"
26
  pet_type = None
@@ -42,14 +44,14 @@ def predict(image):
42
  result = f"This is a {pet_type}, the breed is {breed if breed else 'unknown'}.\n" \
43
  f"The probability for it being a {pet_type} is {pet_prob * 100:.2f}%, the probability of being the breed is {breed_prob * 100:.2f}%."
44
 
45
- return result
46
 
47
 
48
  # Define the Gradio interface
49
  iface = gr.Interface(
50
  fn=predict,
51
  inputs=gr.inputs.Image(shape=(224, 224)),
52
- outputs="text",
53
  live=True,
54
  theme="gradio/monochrome",
55
  title="Cat and Dog Image Classifier",
 
21
  # Apply the threshold
22
  threshold = 0.570
23
  classes_with_probs = [(learn.dls.vocab[i], probs[i].item()) for i in range(len(mask)) if probs[i] > threshold]
24
+ confidences = {learn.dls.vocab[i]: float(probs[i].item()) for i in range(len(probs)) if probs[i] > threshold}
25
+
26
 
27
  # Check if the prediction includes "dog" or "cat"
28
  pet_type = None
 
44
  result = f"This is a {pet_type}, the breed is {breed if breed else 'unknown'}.\n" \
45
  f"The probability for it being a {pet_type} is {pet_prob * 100:.2f}%, the probability of being the breed is {breed_prob * 100:.2f}%."
46
 
47
+ return result, confidences
48
 
49
 
50
  # Define the Gradio interface
51
  iface = gr.Interface(
52
  fn=predict,
53
  inputs=gr.inputs.Image(shape=(224, 224)),
54
+ outputs=[gr.outputs.Textbox(label="Prediction"), gr.outputs.Label(label='confidences',num_top_classes=2)],
55
  live=True,
56
  theme="gradio/monochrome",
57
  title="Cat and Dog Image Classifier",