Spaces:
Sleeping
Sleeping
Update app.py
Browse files56 unmodified lines5758596061626364656667686970717273747576777860616225 unmodified lines88899011011111211311411511611711811991929356 unmodified lines
"""
# model_key = "CLIP-large"
# Load model (cache for speed)if model_key not in MODEL_CACHE: MODEL_CACHE[model_key] = pipeline(task = "zero-shot-image-classification", model = MODEL_OPTIONS[model_key])classifier = MODEL_CACHE[model_key]
BASE_DIR = '/content/drive/MyDrive/ML Projects/Zero-shot Image Classification/Images'image_path = os.path.join(BASE_DIR, 'Mouse1_2.png')
output = classifier( image = image_path, candidate_labels = CANDIDATE_LABELS, hypothesis_template = "This image shows {}")
# print("\n\n=============================================================================")# print(f"\nPrediction: This image shows {output[0]["label"]} | Confidence (probability): {100*output[0]["score"]: .1f}%")
def run_classifer(model_key, image_path, prob_threshold = None): # model_key: name of backbone zero-shot-image-classification model to use # image_path: path to test image25 unmodified lines
return predicted_label_str, prob_dict
# # example run# model_key = "CLIP-large"# BASE_DIR = '/content/drive/MyDrive/ML Projects/Zero-shot Image Classification/Images'# image_path = os.path.join(BASE_DIR, 'Nail2_1.png')
# predicted_label_str, prob_dict = run_classifer(model_key, image_path, prob_threshold = 0.4)# print("\n\n=============================================================================")# # print(f"\nPrediction: {predicted_label_str} | Confidence (probability): {100*output[0]['score']:.1f}%")# print(f"\nPrediction: {predicted_label_str}")
"""### Gradio App
---app.py-29