Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForImageClassification, pipeline, AutoImageProcessor
|
3 |
+
from torchvision import transforms
|
4 |
+
|
5 |
+
model = AutoModelForImageClassification.from_pretrained("Nicole-M/Dataset1-SwinV2")
|
6 |
+
image_processor = AutoImageProcessor.from_pretrained("Nicole-M/Dataset1-SwinV2")
|
7 |
+
clf = pipeline(model=model, task="image-classification", image_processor=image_processor)
|
8 |
+
|
9 |
+
class_names = ['Benign', 'Malignant']
|
10 |
+
|
11 |
+
def predict_image(img):
|
12 |
+
img = transforms.ToPILImage()(img)
|
13 |
+
img = transforms.Resize((224,224))(img)
|
14 |
+
prediction=clf.predict(img)
|
15 |
+
return {class_names[i]: float(prediction[i]["score"]) for i in range(2)}
|
16 |
+
|
17 |
+
image = gr.Image(label="Select a mammogram image", sources=['upload'])
|
18 |
+
label = gr.Label(num_top_classes=2)
|
19 |
+
|
20 |
+
gr.Interface(fn=predict_image, inputs=image, outputs=label, title="Mammogram classification").launch()
|