Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -21,33 +21,36 @@ models = {
|
|
21 |
|
22 |
modality_keys = ['Ultrasound', 'OCT', 'Fundus', 'Fluorescence']
|
23 |
|
24 |
-
def classify_images(img_ultrasound
|
25 |
imgs = [img_ultrasound, img_oct, img_fundus, img_fluorescence]
|
26 |
predictions = []
|
27 |
detailed_predictions = [] # To store detailed predictions for each modality
|
|
|
|
|
28 |
|
29 |
-
if not
|
30 |
return "Please upload at least one image for prediction."
|
31 |
|
32 |
-
# Convert images to PILImage and predict with each model
|
33 |
for img, key in zip(imgs, modality_keys):
|
34 |
-
if img is not None:
|
35 |
pil_img = PILImage.create(img)
|
36 |
pred, _, probs = models[key].predict(pil_img)
|
37 |
-
predictions.append(pred)
|
38 |
prob_pred = probs.max() # Get the highest probability score
|
39 |
-
|
|
|
40 |
else:
|
41 |
detailed_predictions.append(f"{key}: No image provided")
|
42 |
-
|
|
|
43 |
|
44 |
return "\n".join(detailed_predictions)
|
45 |
|
46 |
-
# Define the Gradio interface inputs
|
47 |
-
inputs = [gr.Image(label=f"{modality} Image"
|
48 |
output = gr.Text(label="Predictions")
|
49 |
|
50 |
intf = gr.Interface(fn=classify_images, inputs=inputs, outputs=output,
|
51 |
title="ODD Detection from Multiple Imaging Modalities",
|
52 |
-
description="Upload images for each modality (as available)
|
53 |
intf.launch(share=True)
|
|
|
21 |
|
22 |
modality_keys = ['Ultrasound', 'OCT', 'Fundus', 'Fluorescence']
|
23 |
|
24 |
+
def classify_images(img_ultrasound, img_oct, img_fundus, img_fluorescence):
|
25 |
imgs = [img_ultrasound, img_oct, img_fundus, img_fluorescence]
|
26 |
predictions = []
|
27 |
detailed_predictions = [] # To store detailed predictions for each modality
|
28 |
+
|
29 |
+
provided_imgs = [img for img in imgs if img is not None]
|
30 |
|
31 |
+
if not provided_imgs: # Check if no images were provided
|
32 |
return "Please upload at least one image for prediction."
|
33 |
|
34 |
+
# Convert provided images to PILImage and predict with each model
|
35 |
for img, key in zip(imgs, modality_keys):
|
36 |
+
if img is not None:
|
37 |
pil_img = PILImage.create(img)
|
38 |
pred, _, probs = models[key].predict(pil_img)
|
|
|
39 |
prob_pred = probs.max() # Get the highest probability score
|
40 |
+
predictions.append(pred)
|
41 |
+
detailed_predictions.append(f"{key}: {pred} ({prob_pred.item()*100:.2f}%)")
|
42 |
else:
|
43 |
detailed_predictions.append(f"{key}: No image provided")
|
44 |
+
|
45 |
+
# Final decision logic here, if applicable
|
46 |
|
47 |
return "\n".join(detailed_predictions)
|
48 |
|
49 |
+
# Define the Gradio interface inputs without using 'optional=True'
|
50 |
+
inputs = [gr.Image(label=f"{modality} Image") for modality in modality_keys]
|
51 |
output = gr.Text(label="Predictions")
|
52 |
|
53 |
intf = gr.Interface(fn=classify_images, inputs=inputs, outputs=output,
|
54 |
title="ODD Detection from Multiple Imaging Modalities",
|
55 |
+
description="Upload images for each modality (as available). It's not required to upload an image for every input field. At least one image is required for a prediction.")
|
56 |
intf.launch(share=True)
|