from fastai.vision.all import * import gradio as gr from pathlib import Path import pandas as pd def get_x(row): # All files are assumed to be '.jpg', so we directly return the path with '.jpg' extension return path_image_combined / f"{row['file_name']}.jpg" def get_y(row): return row['Buried ODD'] # Load the models into a dictionary models = { 'Ultrasound': load_learner('ODDUltrasound.pkl'), 'OCT': load_learner('ODDOCT.pkl'), 'Fundus': load_learner('ODDfundus.pkl'), 'Fluorescence': load_learner('ODDfluorescence.pkl') } modality_keys = ['Ultrasound', 'OCT', 'Fundus', 'Fluorescence'] def classify_images(img_ultrasound, img_oct, img_fundus, img_fluorescence): imgs = [img_ultrasound, img_oct, img_fundus, img_fluorescence] predictions = [] # Convert images to PILImage and predict with each model for img, key in zip(imgs, modality_keys): pil_img = PILImage.create(img) pred, _, _ = models[key].predict(pil_img) predictions.append(pred) # Majority vote for final decision final_decision = max(set(predictions), key=predictions.count) return f"ODD Detection: {final_decision}" # Define the Gradio interface inputs = [gr.Image(shape=(192, 192), label=f"{modality} Image") for modality in modality_keys] output = gr.Text(label="Final Decision") intf = gr.Interface(fn=classify_images, inputs=inputs, outputs=output, title="ODD Detection from Multiple Imaging Modalities", description="Upload images for each modality and receive a binary prediction for Optic Disk Drusen presence.") intf.launch(share=True)