Spaces:
Sleeping
Sleeping
File size: 1,831 Bytes
7901ba4 419e1eb f2a6c90 419e1eb 510f06a aaa6c62 510f06a 419e1eb b57d730 419e1eb 510f06a 419e1eb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
import gradio as gr
import yolov5
import os
from transformers import pipeline
imageClassifier = pipeline(task="image-classification",
model="Ara88/timri-model")
model = yolov5.load('./gentle-meadow.pt', device="cpu")
def predict(image):
predictions = imageClassifier(image)
maxScore = 0
predictedLabel = None
labelsForLocalization = ['meningioma', 'pituitary']
output = {}
for item in predictions:
output[item['label']] = item['score']
if (maxScore < item['score']):
maxScore = item['score']
predictedLabel = item['label']
if (predictedLabel in labelsForLocalization):
results = model([image], size=224)
imageWithLocalization = results.render()[0]
else:
imageWithLocalization = image
return output, imageWithLocalization
title = "Detecting Tumors in MRI Images"
description = """
Try the examples at bottom to get started.
"""
examples = [
[os.path.abspath('examples/sample_1.jpg')],
[os.path.abspath('examples/sample_2.jpg')],
[os.path.abspath('examples/sample_3.jpg')],
[os.path.abspath('examples/sample_4.jpg')],
[os.path.abspath('examples/sample_5.jpg')],
[os.path.abspath('examples/sample_6.jpg')],
[os.path.abspath('examples/sample_7.jpg')],
[os.path.abspath('examples/sample_8.jpg')],
]
inputs = gr.Image(type="pil", shape=(224, 224),
label="Upload your image for detection")
outputs = [
gr.Label(label="Tumor Classification"),
gr.Image(type="pil", label="Tumor Detections")
]
interface = gr.Interface(
fn=predict,
inputs=inputs,
outputs=outputs,
title=title,
examples=examples,
description=description,
cache_examples=True,
theme='huggingface'
)
interface.launch(debug=True, enable_queue=True)
|