Spaces:
Build error
Build error
Ethan MacCumber commited on
Commit ·
3092c67
1
Parent(s): c1eace2
cleaning up
Browse files- app.py +42 -79
- export.pkl +0 -3
- healthy.jpg +0 -0
- macroaneurism.jpg +0 -0
- sick_eye.jpeg +0 -0
app.py
CHANGED
|
@@ -1,80 +1,43 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 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 |
-
# '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)
|
|
|