Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -57,7 +57,7 @@ LABELS_MAP = ["Bat (baseball)", "Bat (mammal)",
|
|
| 57 |
|
| 58 |
"""
|
| 59 |
|
| 60 |
-
def run_classifer(model_key, image_path):
|
| 61 |
# model_key: name of backbone zero-shot-image-classification model to use
|
| 62 |
# image_path: path to test image
|
| 63 |
# prob_threshold: confidence (i.e., probability) threshold above which to consider a prediction valid
|
|
@@ -87,8 +87,8 @@ def run_classifer(model_key, image_path):
|
|
| 87 |
# Dictionary mapping all candidate labels to their predicted probabilities
|
| 88 |
prob_dict = {label_lookup[output['label']]: round(output["score"], 4) for output in outputs}
|
| 89 |
|
| 90 |
-
|
| 91 |
-
predicted_label_str = f"This image shows {outputs[0]['label']} | Confidence (probability): {100*outputs[0]['score']:.1f}%"
|
| 92 |
|
| 93 |
return predicted_label_str, prob_dict
|
| 94 |
|
|
@@ -111,7 +111,7 @@ gradio_app = gradio.Interface(
|
|
| 111 |
fn = run_classifer,
|
| 112 |
inputs = [gradio.Dropdown(["CLIP-base", "CLIP-large", "SigLIP-base", "SigLIP-large"], value="CLIP-large", label = "Select Classifier"),
|
| 113 |
gradio.Image(type="pil", label="Load sample image here"),
|
| 114 |
-
|
| 115 |
],
|
| 116 |
|
| 117 |
outputs = [gradio.Textbox(label="Image Classification"),
|
|
|
|
| 57 |
|
| 58 |
"""
|
| 59 |
|
| 60 |
+
def run_classifer(model_key, image_path, prob_threshold):
|
| 61 |
# model_key: name of backbone zero-shot-image-classification model to use
|
| 62 |
# image_path: path to test image
|
| 63 |
# prob_threshold: confidence (i.e., probability) threshold above which to consider a prediction valid
|
|
|
|
| 87 |
# Dictionary mapping all candidate labels to their predicted probabilities
|
| 88 |
prob_dict = {label_lookup[output['label']]: round(output["score"], 4) for output in outputs}
|
| 89 |
|
| 90 |
+
predicted_label_str = f"This image shows {outputs[0]['label']} | Confidence (probability): {100*outputs[0]['score']:.1f}%" if float(outputs[0]['score']) > prob_threshold else "No prediction"
|
| 91 |
+
# predicted_label_str = f"This image shows {outputs[0]['label']} | Confidence (probability): {100*outputs[0]['score']:.1f}%"
|
| 92 |
|
| 93 |
return predicted_label_str, prob_dict
|
| 94 |
|
|
|
|
| 111 |
fn = run_classifer,
|
| 112 |
inputs = [gradio.Dropdown(["CLIP-base", "CLIP-large", "SigLIP-base", "SigLIP-large"], value="CLIP-large", label = "Select Classifier"),
|
| 113 |
gradio.Image(type="pil", label="Load sample image here"),
|
| 114 |
+
gradio.Slider(minimum = 0.1, maximum = 0.9, step = 0.05, value = 0.25, label = "Set Prediction Threshold")
|
| 115 |
],
|
| 116 |
|
| 117 |
outputs = [gradio.Textbox(label="Image Classification"),
|