Spaces:
Sleeping
Sleeping
Ethan MacCumber
commited on
Commit
·
ddfba2f
1
Parent(s):
527a2b6
trying altair
Browse files
app.py
CHANGED
@@ -1,47 +1,63 @@
|
|
1 |
import gradio as gr
|
2 |
from fastai.vision.all import *
|
3 |
-
import
|
4 |
-
import
|
5 |
|
6 |
-
|
|
|
7 |
|
8 |
def predict_and_plot(img):
|
9 |
-
|
10 |
pred, pred_idx, probs = learn.predict(img)
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
27 |
probs_np = probs.numpy()
|
28 |
-
|
29 |
threshold = 0.5
|
30 |
-
|
31 |
present = probs_np > threshold
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
# Create the Gradio interface
|
47 |
interface = gr.Interface(
|
@@ -53,6 +69,6 @@ interface = gr.Interface(
|
|
53 |
)
|
54 |
|
55 |
# Launch the app
|
56 |
-
|
57 |
-
|
58 |
|
|
|
1 |
import gradio as gr
|
2 |
from fastai.vision.all import *
|
3 |
+
import altair as alt
|
4 |
+
import pandas as pd
|
5 |
|
6 |
+
# Load your trained FastAI model
|
7 |
+
learn = load_learner('export.pkl')
|
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(
|
|
|
69 |
)
|
70 |
|
71 |
# Launch the app
|
72 |
+
if __name__ == "__main__":
|
73 |
+
interface.launch()
|
74 |
|