IFMedTechdemo's picture
Update app.py
4e66ca3 verified
Raw
History Blame Contribute Delete
1.29 kB
import gradio as gr
from PIL import Image
from transformers import pipeline
MODEL_NAME = "openai/clip-vit-large-patch14"
DEFAULT_LABELS = [
"melasma skin pigmentation",
"ringworm skin infection ring shape",
"eczema inflamed dry skin",
"acne pimple pustule",
"normal skin",
"birthmark on skin",
"shadow on skin",
"insect bite on skin",
"sunburned skin",
"hair",
"clothing fabric",
"background object",
"medical instrument",
"paper",
"office table",
]
classifier = pipeline("zero-shot-image-classification", model=MODEL_NAME)
def detect(image):
if image is None:
return ""
pil_image = Image.fromarray(image)
results = classifier(pil_image, candidate_labels=DEFAULT_LABELS)
lines = []
for item in results:
lines.append(f"{item['score']:.4f} {item['label']}")
return "\n".join(lines)
demo = gr.Interface(
fn=detect,
inputs=gr.Image(label="Upload Skin Image"),
outputs=gr.Textbox(label="CLIP Probabilities", lines=len(DEFAULT_LABELS)),
title="Skin Disease Detection with CLIP",
description="Zero-shot classification using openai/clip-vit-large-patch14. Shows probability scores for each label.",
examples=[],
)
if __name__ == "__main__":
demo.launch()