File size: 1,498 Bytes
546f352
0bda39c
 
546f352
e2f6cfc
1587eea
 
 
c10710a
 
546f352
e2f6cfc
 
 
 
 
 
 
 
 
546f352
c10710a
 
e2f6cfc
 
546f352
7b2689f
7669f3a
546f352
 
 
 
 
 
 
 
 
 
 
 
e2f6cfc
 
 
 
546f352
67daaca
 
52c8a54
0387452
e2f6cfc
 
 
 
67daaca
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
import gradio as gr
from fastai.vision.all import *
import skimage

def get_x(r): return ""
        
def get_y(r): return r['diagnosis']

learn = load_learner('model.pkl')
labels = learn.dls.vocab

# Define the mapping from label numbers to descriptions
label_descriptions = {
    0: "No DR",
    1: "Mild",
    2: "Moderate",
    3: "Severe",
    4: "Proliferative DR"
}

def predict(img):
    img = PILImage.create(img)
    pred,pred_idx,probs = learn.predict(img)
    # Use the label_descriptions dictionary to return descriptions instead of numbers
    return {label_descriptions[labels[i]]: float(probs[i]) for i in range(len(labels))}

title = "Diabetic Retinopathy Detection"
description = """Detects severity of diabetic retinopathy -

    0 - No DR

    1 - Mild

    2 - Moderate

    3 - Severe

    4 - Proliferative DR
"""
article="<p style='text-align: center'><a href='https://www.kaggle.com/code/josemauriciodelgado/proliferative-retinopathy' target='_blank'>Notebook</a></p>"

# Get a list of all image paths in the test folder
test_folder = "test"  # replace with the actual path to your test folder
image_paths = [os.path.join(test_folder, img) for img in os.listdir(test_folder) if img.endswith(('.png', '.jpg', '.jpeg'))]

gr.Interface(
    fn=predict,
    inputs=gr.Image(),
    outputs=gr.Label(num_top_classes=5),
    examples=image_paths,  # set the examples parameter to the list of image paths
    article=article,
    title=title,
    description=description,
).launch()