Spaces:
Runtime error
Runtime error
Download app.py from Nicole-M/Mammogram-classification: direct link, hf CLI and curl.
- Browser
- Download file 851 Bytes
-
https://huggingface.co/spaces/Nicole-M/Mammogram-classification/resolve/main/app.py
- Command line
-
hf download hf://spaces/Nicole-M/Mammogram-classification/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Nicole-M/Mammogram-classification/resolve/main/app.py
851 Bytes
| 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() |