Ethan MacCumber commited on
Commit
3092c67
·
1 Parent(s): c1eace2

cleaning up

Browse files
Files changed (5) hide show
  1. app.py +42 -79
  2. export.pkl +0 -3
  3. healthy.jpg +0 -0
  4. macroaneurism.jpg +0 -0
  5. sick_eye.jpeg +0 -0
app.py CHANGED
@@ -1,80 +1,43 @@
1
  import gradio as gr
2
- from fastai.vision.all import *
3
- import matplotlib.pyplot as plt
4
- import numpy as np
5
- from transformers import pipeline
6
- from huggingface_hub import from_pretrained_fastai
7
-
8
- pipe = pipeline(
9
- task="image-classification",
10
- model ="ethanmac/dr-maclboomber-retina-classifier",
11
- description="Retinal Condition Classifier",
12
- examples=['sick-eye.jpeg', 'healthy.jpg']
13
- ).launch()
14
-
15
-
16
- # from huggingface_hub import from_pretrained_fastai
17
-
18
- # # repo_id = "YOUR_USERNAME/YOUR_LEARNER_NAME"
19
- # repo_id = "espejelomar/identify-my-cat"
20
-
21
- # learner = from_pretrained_fastai(repo_id)
22
-
23
-
24
-
25
-
26
-
27
-
28
- # # Load your trained FastAI model
29
- # learn = load_learner('export.pkl')
30
-
31
- # def predict_and_plot(img):
32
- # # Get predictions
33
- # pred, pred_idx, probs = learn.predict(img)
34
- # # Get class names
35
- # class_names = ['Normal',
36
- # 'Hollenhorst Emboli',
37
- # 'Hypertensive Retinopathy',
38
- # 'Coat\'s',
39
- # 'Macroaneurism',
40
- # 'Choroidal Neovascularization',
41
- # 'Other',
42
- # 'Branch Retinal Artery Occlusion',
43
- # 'Cilio-Retinal Artery Occlusion',
44
- # 'Branch Retinal Vein Occlusion',
45
- # 'Central Retinal Vein Occlusion',
46
- # 'Hemi-Central Retinal Vein Occlusion',
47
- # 'Background Diabetic Retinopathy',
48
- # 'Proliferative Diabetic Retinopathy',
49
- # 'Arteriosclerotic Retinopathy']
50
- # probs_np = probs.numpy()
51
-
52
- # threshold = 0.5
53
-
54
- # present = probs_np > threshold
55
- # fig, ax = plt.subplots(figsize=(10, 6))
56
- # y_pos = np.arange(len(class_names))
57
-
58
- # colors = ['green' if is_present else 'red' for is_present in present]
59
- # ax.barh(y_pos, probs_np, color=colors)
60
- # ax.set_yticks(y_pos)
61
- # ax.set_yticklabels(class_names)
62
- # ax.invert_yaxis()
63
- # ax.set_xlabel('Probability')
64
- # ax.set_xlim(0, 1)
65
- # ax.set_title('Predicted Probabilities for Each Condition')
66
- # plt.tight_layout()
67
- # return fig
68
-
69
- # # Create the Gradio interface
70
- # interface = gr.Interface(
71
- # fn=predict_and_plot,
72
- # inputs=gr.Image(type='pil'),
73
- # outputs=gr.Plot(),
74
- # title="Dr. Macloomber",
75
- # description="Upload an image of a retina to predict the probabilities of various eye conditions."
76
- # )
77
-
78
- # # Launch the app
79
- # interface.launch()
80
-
 
1
  import gradio as gr
2
+ from huggingface_hub import hf_hub_download
3
+ from fastai.learner import load_learner
4
+
5
+ repo_id = "ethanmac/dr-macbloomber-retina-condition-classifier"
6
+
7
+ model = load_learner(
8
+ hf_hub_download(repo_id, "model.pkl")
9
+ )
10
+
11
+ class_names = [
12
+ 'Normal',
13
+ 'Hollenhorst Emboli',
14
+ 'Hypertensive Retinopathy',
15
+ 'Coat\'s',
16
+ 'Macroaneurism',
17
+ 'Choroidal Neovascularization',
18
+ 'Other',
19
+ 'Branch Retinal Artery Occlusion',
20
+ 'Cilio-Retinal Artery Occlusion',
21
+ 'Branch Retinal Vein Occlusion',
22
+ 'Central Retinal Vein Occlusion',
23
+ 'Hemi-Central Retinal Vein Occlusion',
24
+ 'Background Diabetic Retinopathy',
25
+ 'Proliferative Diabetic Retinopathy',
26
+ 'Arteriosclerotic Retinopathy'
27
+ ]
28
+
29
+ categories = [c.replace('_', ' ').title() for c in class_names]
30
+
31
+ def classify_image(img):
32
+ pred, idx, probs = model.predict(img)
33
+ out = dict(zip(categories, map(float, probs)))
34
+ return out
35
+
36
+ intf = gr.Interface(
37
+ fn=classify_image,
38
+ inputs=gr.Image(),
39
+ outputs=gr.Label(num_top_classes=5),
40
+ examples=['healthy.jpg', 'macroaneurism.jpg']
41
+ )
42
+
43
+ intf.launch(inline=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
export.pkl DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:77458acaeca030340762d1abaeb82968614bac52b777813e37b4b0576e61d7b0
3
- size 47019902
 
 
 
 
healthy.jpg CHANGED
macroaneurism.jpg ADDED
sick_eye.jpeg DELETED
Binary file (5.02 kB)