Spaces:
Sleeping
Sleeping
Update app_2.py
Browse files
app_2.py
CHANGED
@@ -1,3 +1,5 @@
|
|
|
|
|
|
1 |
from pathlib import Path
|
2 |
import pandas as pd
|
3 |
|
@@ -6,4 +8,45 @@ def get_x(row):
|
|
6 |
return path_image_combined / f"{row['file_name']}.jpg"
|
7 |
|
8 |
def get_y(row):
|
9 |
-
return row['Buried ODD']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastai.vision.all import *
|
2 |
+
import gradio as gr
|
3 |
from pathlib import Path
|
4 |
import pandas as pd
|
5 |
|
|
|
8 |
return path_image_combined / f"{row['file_name']}.jpg"
|
9 |
|
10 |
def get_y(row):
|
11 |
+
return row['Buried ODD']
|
12 |
+
|
13 |
+
# Load the models into a dictionary
|
14 |
+
models = {
|
15 |
+
'Ultrasound': load_learner('ODDUltrasound.pkl'),
|
16 |
+
'OCT': load_learner('ODDOCT.pkl'),
|
17 |
+
'Fundus': load_learner('ODDfundus.pkl'),
|
18 |
+
'Fluorescence': load_learner('ODDfluorescence.pkl')
|
19 |
+
}
|
20 |
+
|
21 |
+
modality_keys = ['Ultrasound', 'OCT', 'Fundus', 'Fluorescence']
|
22 |
+
|
23 |
+
def classify_images(img_ultrasound, img_oct, img_fundus, img_fluorescence):
|
24 |
+
imgs = [img_ultrasound, img_oct, img_fundus, img_fluorescence]
|
25 |
+
predictions = []
|
26 |
+
detailed_predictions = [] # To store detailed predictions for each modality
|
27 |
+
|
28 |
+
# Convert images to PILImage and predict with each model
|
29 |
+
for img, key in zip(imgs, modality_keys):
|
30 |
+
pil_img = PILImage.create(img)
|
31 |
+
pred, _, probs = models[key].predict(pil_img)
|
32 |
+
predictions.append(pred)
|
33 |
+
|
34 |
+
# Assuming binary classification, extract the probability for the predicted class
|
35 |
+
prob_pred = probs.max() # Get the highest probability score
|
36 |
+
detailed_predictions.append(f"{key}: {pred} ({prob_pred:.2f}%)") # Format prediction with percentage
|
37 |
+
|
38 |
+
# Majority vote for final decision
|
39 |
+
final_decision = max(set(predictions), key=predictions.count)
|
40 |
+
|
41 |
+
detailed_predictions.append(f"Final Decision: {final_decision}") # Add the final decision
|
42 |
+
|
43 |
+
return "\n".join(detailed_predictions) # Return detailed predictions as a single string
|
44 |
+
|
45 |
+
# Define the Gradio interface inputs and outputs
|
46 |
+
inputs = [gr.Image(label=f"{modality} Image") for modality in modality_keys]
|
47 |
+
output = gr.Text(label="Predictions")
|
48 |
+
|
49 |
+
intf = gr.Interface(fn=classify_images, inputs=inputs, outputs=output,
|
50 |
+
title="ODD Detection from Multiple Imaging Modalities",
|
51 |
+
description="Upload images for each modality and receive individual predictions with percentages and a binary prediction for Optic Disk Drusen presence.")
|
52 |
+
intf.launch(share=True)
|