Spaces:
Sleeping
Sleeping
Ethan MacCumber
commited on
Commit
·
d7c6ecd
1
Parent(s):
ddfba2f
trying something simple
Browse files- app.py +65 -67
- healthy.jpg +0 -0
- sick_eye.jpeg +0 -0
app.py
CHANGED
@@ -1,74 +1,72 @@
|
|
1 |
import gradio as gr
|
2 |
from fastai.vision.all import *
|
3 |
-
import
|
4 |
-
import
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
def predict_and_plot(img):
|
10 |
-
# Get predictions
|
11 |
-
pred, pred_idx, probs = learn.predict(img)
|
12 |
-
|
13 |
-
# Define class names
|
14 |
-
class_names = [
|
15 |
-
'Normal',
|
16 |
-
'Hollenhorst Emboli',
|
17 |
-
'Hypertensive Retinopathy',
|
18 |
-
"Coat's",
|
19 |
-
'Macroaneurism',
|
20 |
-
'Choroidal Neovascularization',
|
21 |
-
'Other',
|
22 |
-
'Branch Retinal Artery Occlusion',
|
23 |
-
'Cilio-Retinal Artery Occlusion',
|
24 |
-
'Branch Retinal Vein Occlusion',
|
25 |
-
'Central Retinal Vein Occlusion',
|
26 |
-
'Hemi-Central Retinal Vein Occlusion',
|
27 |
-
'Background Diabetic Retinopathy',
|
28 |
-
'Proliferative Diabetic Retinopathy',
|
29 |
-
'Arteriosclerotic Retinopathy'
|
30 |
-
]
|
31 |
-
|
32 |
-
# Convert probabilities to numpy array
|
33 |
-
probs_np = probs.numpy()
|
34 |
-
threshold = 0.5
|
35 |
-
present = probs_np > threshold
|
36 |
-
|
37 |
-
# Create a DataFrame with the results
|
38 |
-
df = pd.DataFrame({
|
39 |
-
'Condition': class_names,
|
40 |
-
'Probability': probs_np,
|
41 |
-
'Present': present
|
42 |
-
})
|
43 |
-
|
44 |
-
# Create an Altair bar chart
|
45 |
-
chart = alt.Chart(df).mark_bar().encode(
|
46 |
-
x=alt.X('Probability:Q', scale=alt.Scale(domain=(0, 1))),
|
47 |
-
y=alt.Y('Condition:N', sort='-x'),
|
48 |
-
color=alt.condition(
|
49 |
-
alt.datum.Present,
|
50 |
-
alt.value('green'), # Color for conditions present
|
51 |
-
alt.value('red') # Color for conditions not present
|
52 |
-
)
|
53 |
-
).properties(
|
54 |
-
title='Predicted Probabilities for Each Condition',
|
55 |
-
width=600,
|
56 |
-
height=400
|
57 |
-
)
|
58 |
-
|
59 |
-
# Return the chart
|
60 |
-
return chart
|
61 |
|
62 |
-
# Create the Gradio interface
|
63 |
-
interface = gr.Interface(
|
64 |
-
fn=predict_and_plot,
|
65 |
-
inputs=gr.Image(type='pil'),
|
66 |
-
outputs=gr.Plot(),
|
67 |
-
title="Dr. Macloomber",
|
68 |
-
description="Upload an image of a retina to predict the probabilities of various eye conditions."
|
69 |
-
)
|
70 |
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
|
|
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 |
|
7 |
+
pipe = pipeline(
|
8 |
+
task="image-classification",
|
9 |
+
model ="export.pkl",
|
10 |
+
description="Retinal Condition Classifier",
|
11 |
+
examples=['sick-eye.jpeg', 'healthy.jpg']
|
12 |
+
).launch()
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
|
17 |
+
|
18 |
+
|
19 |
+
|
20 |
+
# # Load your trained FastAI model
|
21 |
+
# learn = load_learner('export.pkl')
|
22 |
+
|
23 |
+
# def predict_and_plot(img):
|
24 |
+
# # Get predictions
|
25 |
+
# pred, pred_idx, probs = learn.predict(img)
|
26 |
+
# # Get class names
|
27 |
+
# class_names = ['Normal',
|
28 |
+
# 'Hollenhorst Emboli',
|
29 |
+
# 'Hypertensive Retinopathy',
|
30 |
+
# 'Coat\'s',
|
31 |
+
# 'Macroaneurism',
|
32 |
+
# 'Choroidal Neovascularization',
|
33 |
+
# 'Other',
|
34 |
+
# 'Branch Retinal Artery Occlusion',
|
35 |
+
# 'Cilio-Retinal Artery Occlusion',
|
36 |
+
# 'Branch Retinal Vein Occlusion',
|
37 |
+
# 'Central Retinal Vein Occlusion',
|
38 |
+
# 'Hemi-Central Retinal Vein Occlusion',
|
39 |
+
# 'Background Diabetic Retinopathy',
|
40 |
+
# 'Proliferative Diabetic Retinopathy',
|
41 |
+
# 'Arteriosclerotic Retinopathy']
|
42 |
+
# probs_np = probs.numpy()
|
43 |
+
|
44 |
+
# threshold = 0.5
|
45 |
+
|
46 |
+
# present = probs_np > threshold
|
47 |
+
# fig, ax = plt.subplots(figsize=(10, 6))
|
48 |
+
# y_pos = np.arange(len(class_names))
|
49 |
+
|
50 |
+
# colors = ['green' if is_present else 'red' for is_present in present]
|
51 |
+
# ax.barh(y_pos, probs_np, color=colors)
|
52 |
+
# ax.set_yticks(y_pos)
|
53 |
+
# ax.set_yticklabels(class_names)
|
54 |
+
# ax.invert_yaxis()
|
55 |
+
# ax.set_xlabel('Probability')
|
56 |
+
# ax.set_xlim(0, 1)
|
57 |
+
# ax.set_title('Predicted Probabilities for Each Condition')
|
58 |
+
# plt.tight_layout()
|
59 |
+
# return fig
|
60 |
+
|
61 |
+
# # Create the Gradio interface
|
62 |
+
# interface = gr.Interface(
|
63 |
+
# fn=predict_and_plot,
|
64 |
+
# inputs=gr.Image(type='pil'),
|
65 |
+
# outputs=gr.Plot(),
|
66 |
+
# title="Dr. Macloomber",
|
67 |
+
# description="Upload an image of a retina to predict the probabilities of various eye conditions."
|
68 |
+
# )
|
69 |
+
|
70 |
+
# # Launch the app
|
71 |
+
# interface.launch()
|
72 |
|
healthy.jpg
ADDED
![]() |
sick_eye.jpeg
ADDED
![]() |