Ethium commited on
Commit
374cd0b
1 Parent(s): 288c418

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -28
app.py CHANGED
@@ -1,17 +1,6 @@
1
  from fastai.vision.all import *
2
  import gradio as gr
3
 
4
- from pathlib import Path
5
- import pandas as pd
6
-
7
- def get_x(row):
8
- # All files are assumed to be '.jpg', so we directly return the path with '.jpg' extension
9
- return path_image_combined / f"{row['file_name']}.jpg"
10
-
11
- def get_y(row):
12
- return row['Buried ODD']
13
-
14
-
15
  # Load the models into a dictionary
16
  models = {
17
  'Ultrasound': load_learner('ODDUltrasound.pkl'),
@@ -22,33 +11,39 @@ models = {
22
 
23
  modality_keys = ['Ultrasound', 'OCT', 'Fundus', 'Fluorescence']
24
 
25
- def classify_images(img_ultrasound, img_oct, img_fundus, img_fluorescence):
26
  imgs = [img_ultrasound, img_oct, img_fundus, img_fluorescence]
27
  predictions = []
28
  detailed_predictions = [] # To store detailed predictions for each modality
29
 
30
- # Convert images to PILImage and predict with each model
31
- for img, key in zip(imgs, modality_keys):
32
- pil_img = PILImage.create(img)
33
- pred, _, probs = models[key].predict(pil_img)
34
- predictions.append(pred)
35
-
36
- # Assuming binary classification, extract the probability for the predicted class
37
- prob_pred = probs.max() # Get the highest probability score
38
- detailed_predictions.append(f"{key}: {pred} ({prob_pred:.2f}%)") # Format prediction with percentage
39
 
40
- # Majority vote for final decision
41
- final_decision = max(set(predictions), key=predictions.count)
 
 
 
 
 
 
 
 
42
 
43
- detailed_predictions.append(f"Final Decision: {final_decision}") # Add the final decision
 
 
 
 
 
44
 
45
- return "\n".join(detailed_predictions) # Return detailed predictions as a single string
46
 
47
  # Define the Gradio interface inputs and outputs
48
- inputs = [gr.Image(label=f"{modality} Image") for modality in modality_keys]
49
  output = gr.Text(label="Predictions")
50
 
51
  intf = gr.Interface(fn=classify_images, inputs=inputs, outputs=output,
52
  title="ODD Detection from Multiple Imaging Modalities",
53
- description="Upload images for each modality and receive individual predictions with percentages and a binary prediction for Optic Disk Drusen presence.")
54
- intf.launch(share=True)
 
1
  from fastai.vision.all import *
2
  import gradio as gr
3
 
 
 
 
 
 
 
 
 
 
 
 
4
  # Load the models into a dictionary
5
  models = {
6
  'Ultrasound': load_learner('ODDUltrasound.pkl'),
 
11
 
12
  modality_keys = ['Ultrasound', 'OCT', 'Fundus', 'Fluorescence']
13
 
14
+ def classify_images(img_ultrasound=None, img_oct=None, img_fundus=None, img_fluorescence=None):
15
  imgs = [img_ultrasound, img_oct, img_fundus, img_fluorescence]
16
  predictions = []
17
  detailed_predictions = [] # To store detailed predictions for each modality
18
 
19
+ if not any(imgs): # Check if no images were provided
20
+ return "Please upload at least one image for prediction."
 
 
 
 
 
 
 
21
 
22
+ # Convert images to PILImage and predict with each model, if provided
23
+ for img, key in zip(imgs, modality_keys):
24
+ if img is not None: # Only proceed if an image was uploaded for this modality
25
+ pil_img = PILImage.create(img)
26
+ pred, _, probs = models[key].predict(pil_img)
27
+ predictions.append(pred)
28
+ prob_pred = probs.max() # Get the highest probability score
29
+ detailed_predictions.append(f"{key}: {pred} ({prob_pred:.2f}%)")
30
+ else:
31
+ detailed_predictions.append(f"{key}: No image provided")
32
 
33
+ # Calculate the final decision based on provided predictions, if any
34
+ if predictions:
35
+ final_decision = max(set(predictions), key=predictions.count)
36
+ detailed_predictions.append(f"Final Decision: {final_decision}")
37
+ else:
38
+ detailed_predictions.append("No final decision (Insufficient data)")
39
 
40
+ return "\n".join(detailed_predictions)
41
 
42
  # Define the Gradio interface inputs and outputs
43
+ inputs = [gr.Image(label=f"{modality} Image", optional=True) for modality in modality_keys]
44
  output = gr.Text(label="Predictions")
45
 
46
  intf = gr.Interface(fn=classify_images, inputs=inputs, outputs=output,
47
  title="ODD Detection from Multiple Imaging Modalities",
48
+ 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.")
49
+ intf.launch(share=True)