Ethium commited on
Commit
4eefd61
1 Parent(s): 9e014b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -21,33 +21,36 @@ models = {
21
 
22
  modality_keys = ['Ultrasound', 'OCT', 'Fundus', 'Fluorescence']
23
 
24
- def classify_images(img_ultrasound=None, img_oct=None, img_fundus=None, img_fluorescence=None):
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 any(imgs): # Check if no images were provided
30
  return "Please upload at least one image for prediction."
31
 
32
- # Convert images to PILImage and predict with each model, if provided
33
  for img, key in zip(imgs, modality_keys):
34
- if img is not None: # Only proceed if an image was uploaded for this modality
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
- detailed_predictions.append(f"{key}: {pred} ({prob_pred:.2f}%)")
 
40
  else:
41
  detailed_predictions.append(f"{key}: No image provided")
42
- # Handle final decision logic here as needed
 
43
 
44
  return "\n".join(detailed_predictions)
45
 
46
- # Define the Gradio interface inputs and outputs
47
- inputs = [gr.Image(label=f"{modality} Image", optional=True) for modality in modality_keys]
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) and receive individual predictions with percentages and a binary prediction for Optic Disk Drusen presence. At least one image is required.")
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)