Spaces:
Configuration error
Configuration error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pydicom
|
3 |
+
import numpy as np
|
4 |
+
import matplotlib.pyplot as plt
|
5 |
+
from monai.transforms import Compose, LoadImage, AddChannel, ScaleIntensity, ToTensor
|
6 |
+
|
7 |
+
def interpret_dicom(files):
|
8 |
+
# files: list of uploaded DICOM files
|
9 |
+
slices = []
|
10 |
+
for file in files:
|
11 |
+
ds = pydicom.dcmread(file.name)
|
12 |
+
slices.append(ds.pixel_array)
|
13 |
+
# Sort slices if needed (for CT/MRI)
|
14 |
+
slices = np.array(slices)
|
15 |
+
# Simple visualization: show the middle slice
|
16 |
+
mid_slice = slices[len(slices)//2]
|
17 |
+
plt.imshow(mid_slice, cmap='gray')
|
18 |
+
plt.axis('off')
|
19 |
+
plt.title('Middle Slice')
|
20 |
+
plt.savefig('output.png')
|
21 |
+
plt.close()
|
22 |
+
# Here you would add MONAI model inference
|
23 |
+
# For now, just return the image
|
24 |
+
return 'output.png', "Interpretation: (placeholder)"
|
25 |
+
|
26 |
+
iface = gr.Interface(
|
27 |
+
fn=interpret_dicom,
|
28 |
+
inputs=gr.File(file_count="multiple", label="Upload DICOM files"),
|
29 |
+
outputs=[gr.Image(type="filepath", label="Middle Slice"), gr.Textbox(label="Interpretation")],
|
30 |
+
title="DICOM Radiology Interpreter",
|
31 |
+
description="Upload your DICOM files (e.g., CT scan slices). The app will show the middle slice and provide an interpretation."
|
32 |
+
)
|
33 |
+
|
34 |
+
if __name__ == "__main__":
|
35 |
+
iface.launch()
|