File size: 2,411 Bytes
722fcb5
 
d7c6ecd
 
 
a7c50d6
722fcb5
d7c6ecd
 
a7c50d6
d7c6ecd
 
 
722fcb5
 
a7c50d6
 
 
 
 
 
 
722fcb5
d7c6ecd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
722fcb5
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import gradio as gr
from fastai.vision.all import *
import matplotlib.pyplot as plt
import numpy as np
from transformers import pipeline 
from huggingface_hub import from_pretrained_fastai

pipe = pipeline(
    task="image-classification",
    model ="ethanmac/dr-maclboomber-retina-classifier",
    description="Retinal Condition Classifier",
    examples=['sick-eye.jpeg', 'healthy.jpg']
    ).launch()


# from huggingface_hub import from_pretrained_fastai

# # repo_id = "YOUR_USERNAME/YOUR_LEARNER_NAME"
# repo_id = "espejelomar/identify-my-cat"

# learner = from_pretrained_fastai(repo_id)






# # Load your trained FastAI model
# learn = load_learner('export.pkl') 

# def predict_and_plot(img):
#     # Get predictions
#     pred, pred_idx, probs = learn.predict(img)
#     # Get class names
#     class_names = ['Normal',
#                    'Hollenhorst Emboli',
#                    'Hypertensive Retinopathy',
#                    'Coat\'s',
#                    'Macroaneurism',
#                    'Choroidal Neovascularization',
#                    'Other',
#                    'Branch Retinal Artery Occlusion',
#                    'Cilio-Retinal Artery Occlusion',
#                    'Branch Retinal Vein Occlusion',
#                    'Central Retinal Vein Occlusion',
#                    'Hemi-Central Retinal Vein Occlusion',
#                    'Background Diabetic Retinopathy',
#                    'Proliferative Diabetic Retinopathy',
#                    'Arteriosclerotic Retinopathy']
#     probs_np = probs.numpy()

#     threshold = 0.5

#     present = probs_np > threshold
#     fig, ax = plt.subplots(figsize=(10, 6))
#     y_pos = np.arange(len(class_names))

#     colors = ['green' if is_present else 'red' for is_present in present]
#     ax.barh(y_pos, probs_np, color=colors)
#     ax.set_yticks(y_pos)
#     ax.set_yticklabels(class_names)
#     ax.invert_yaxis()
#     ax.set_xlabel('Probability')
#     ax.set_xlim(0, 1)
#     ax.set_title('Predicted Probabilities for Each Condition')
#     plt.tight_layout()
#     return fig

# # Create the Gradio interface
# interface = gr.Interface(
#     fn=predict_and_plot,
#     inputs=gr.Image(type='pil'),
#     outputs=gr.Plot(),
#     title="Dr. Macloomber",
#     description="Upload an image of a retina to predict the probabilities of various eye conditions."
# )

# # Launch the app
# interface.launch()