Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
import torch
|
| 4 |
+
from torchvision import transforms as T
|
| 5 |
+
|
| 6 |
+
def calc_result_confidence (model_output):
|
| 7 |
+
probs = torch.nn.functional.softmax(model_output, dim=1)
|
| 8 |
+
conf, classes = torch.max(probs, 1)
|
| 9 |
+
|
| 10 |
+
return conf.item(), classes.item()
|
| 11 |
+
|
| 12 |
+
def downsyndrome_gradio_inference(img_file):
|
| 13 |
+
classes = ['Down Syndrome', 'Healty']
|
| 14 |
+
infer_transform = T.Compose([
|
| 15 |
+
T.Resize((255, 255)),
|
| 16 |
+
T.ToTensor(),
|
| 17 |
+
])
|
| 18 |
+
transform_image = infer_transform(img_file.convert('RGB')).float().unsqueeze(0)
|
| 19 |
+
model = pipeline(task='image-classification', model='gitfreder/down-syndrome-detection')
|
| 20 |
+
conf, cls = calc_result_confidence(model(transform_image))
|
| 21 |
+
|
| 22 |
+
return {
|
| 23 |
+
'Predicted': classes[cls],
|
| 24 |
+
'Confidence Score': conf
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
iface = gr.Interface(fn=downsyndrome_gradio_inference, inputs=gr.Image(type='pil'), outputs=gr.JSON(), title="Down Syndrome Detection", description="A model interfaces that detect downsyndrom children from the photo")
|
| 29 |
+
iface.launch()
|