Ravindu9904's picture
Create app.py
81452bc verified
raw
history blame
1.23 kB
import gradio as gr
import pydicom
import numpy as np
import matplotlib.pyplot as plt
from monai.transforms import Compose, LoadImage, AddChannel, ScaleIntensity, ToTensor
def interpret_dicom(files):
# files: list of uploaded DICOM files
slices = []
for file in files:
ds = pydicom.dcmread(file.name)
slices.append(ds.pixel_array)
# Sort slices if needed (for CT/MRI)
slices = np.array(slices)
# Simple visualization: show the middle slice
mid_slice = slices[len(slices)//2]
plt.imshow(mid_slice, cmap='gray')
plt.axis('off')
plt.title('Middle Slice')
plt.savefig('output.png')
plt.close()
# Here you would add MONAI model inference
# For now, just return the image
return 'output.png', "Interpretation: (placeholder)"
iface = gr.Interface(
fn=interpret_dicom,
inputs=gr.File(file_count="multiple", label="Upload DICOM files"),
outputs=[gr.Image(type="filepath", label="Middle Slice"), gr.Textbox(label="Interpretation")],
title="DICOM Radiology Interpreter",
description="Upload your DICOM files (e.g., CT scan slices). The app will show the middle slice and provide an interpretation."
)
if __name__ == "__main__":
iface.launch()