import gradio as gr import torch from utils import * import os model = torch.load('AlzheimerModelCPU.pth') model.eval() def reset(): return None, None, None, None, None with gr.Blocks() as demo: gr.HTML("""
Early Detection of Alzheimer's Disease: A Deep Learning Approach for Accurate Diagnosis.
Alzheimer detection result with Grad-CAM for 3 images. Original, White Matter and Gray Matter image.
""" ) text_area = gr.Textbox(label="Prediction Result") plotarea_original = gr.Plot(label="Original image") plotarea_white = gr.Plot(label="White Matter image") plotarea_gray = gr.Plot(label="Gray Matter image") reset_btn = gr.Button("Reset All Components", variant='stop', scale=1) gr.HTML("""You can select 1 image from the examples and click "Submit".
These images represent 4 different stages of Alzheimer's disease in the following order: Non Demented, Very Mild Demented, Mild Demented and Moderate Demented.
""" ) examples = gr.Examples(examples=[ os.path.join(os.getcwd(), "non.jpg"), os.path.join(os.getcwd(),"verymild.jpg"), os.path.join(os.getcwd(), "mild.jpg"), os.path.join(os.getcwd(), "moderate.jpg")], inputs=image_area, outputs=image_area, label="Examples", ) submit_btn.click(lambda x, target, plot_type: predict_and_gradcam(x, model=model, target=target, plot_type=plot_type), inputs=[image_area, choosen_target, choosen_plottype], outputs=[text_area, plotarea_original, plotarea_white, plotarea_gray]) reset_btn.click(reset, outputs=[image_area, text_area, plotarea_original, plotarea_white, plotarea_gray]) demo.launch()