File size: 1,234 Bytes
81452bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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()