Spaces:
Sleeping
Sleeping
Rename zero_shot_classification.py to app.py
Browse files56 unmodified lines57585960606162639 unmodified lines7374757677767778798026 unmodified lines10710810911011111211311011111211311411511611711811912011511611711811912012156 unmodified lines
"""
model_key = "CLIP-large"# model_key = "CLIP-large"
# Load model (cache for speed)if model_key not in MODEL_CACHE:9 unmodified lines 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}%")# 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 use26 unmodified lines
return predicted_label_str, prob_dict
# example runmodel_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')# # 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}")
prob_dict# 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
zero_shot_classification.py → app.pyRenamed+11-13