Spaces:
Sleeping
Sleeping
File size: 851 Bytes
68b9c58 73be61f 68b9c58 5d091a0 68b9c58 5d091a0 11126b8 68b9c58 e22c4c8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import gradio as gr
from transformers import AutoModelForImageClassification, pipeline, AutoImageProcessor
from torchvision import transforms
model = AutoModelForImageClassification.from_pretrained("Nicole-M/Dataset1-ViT")
image_processor = AutoImageProcessor.from_pretrained("Nicole-M/Dataset1-ViT")
clf = pipeline(model=model, task="image-classification", image_processor=image_processor)
class_names = ['Benign', 'Malignant']
def predict_image(img):
img = transforms.ToPILImage()(img)
img = transforms.Resize((224,224))(img)
prediction=clf.predict(img)
return {class_names[i]: float(prediction[i]["score"]) for i in range(2)}
image = gr.Image(label="Select a mammogram image", sources=['upload'])
label = gr.Label(num_top_classes=2)
gr.Interface(fn=predict_image, inputs=image, outputs=label, title="Mammogram classification").launch() |