AdritRao commited on
Commit
20665dd
·
1 Parent(s): 8c97be5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -23
app.py CHANGED
@@ -6,6 +6,8 @@ import os
6
  import subprocess
7
  from datetime import datetime
8
  import shutil
 
 
9
 
10
  # Flag to track if subprocess commands have been executed
11
  subprocess_executed = False
@@ -52,16 +54,15 @@ def run_inference():
52
 
53
  # Function to read and display the DICOM image
54
  @st.cache_resource
55
- def convert_dicom_to_png(_dicom_data):
56
- # Convert DICOM to a PNG image
57
- plt.imshow(_dicom_data.pixel_array, cmap=plt.cm.bone)
 
 
58
  plt.axis("off")
59
  plt.title("DICOM Image")
60
  plt.tight_layout()
61
- img_buffer = BytesIO()
62
- plt.savefig(img_buffer, format="png")
63
- img_buffer.seek(0)
64
- return img_buffer
65
 
66
  if uploaded_zip_file is not None:
67
  try:
@@ -81,23 +82,15 @@ if uploaded_zip_file is not None:
81
  dicom_files = [os.path.join(temp_dir, f) for f in os.listdir(temp_dir) if f.endswith(".dcm")]
82
  dicom_files.sort() # Sort the files
83
 
84
- if len(dicom_files) == 0:
85
- st.error("No DICOM files found in the ZIP archive.")
86
- else:
87
- # Create a list of DICOM data
88
- dicom_data_list = [pydicom.dcmread(dicom_file) for dicom_file in dicom_files]
89
-
90
- # Convert DICOM slices to PNG frames
91
- png_frames = [convert_dicom_to_png(_dicom_data) for _dicom_data in dicom_data_list]
92
-
93
- # Create a list of image clips from PNG frames
94
- clips = [mp.ImageClip(png_frame, duration=1) for png_frame in png_frames]
95
-
96
- # Concatenate the image clips to create a video
97
- video_clip = mp.concatenate_videoclips(clips, method="compose")
98
 
99
- # Display the video in Streamlit
100
- st.video(video_clip, format="video/mp4")
 
101
 
102
  except Exception as e:
103
  st.error(f"Error: {str(e)}")
 
6
  import subprocess
7
  from datetime import datetime
8
  import shutil
9
+ import moviepy.editor as mp
10
+
11
 
12
  # Flag to track if subprocess commands have been executed
13
  subprocess_executed = False
 
54
 
55
  # Function to read and display the DICOM image
56
  @st.cache_resource
57
+ def display_dicom_image(selected_slice, dicom_files):
58
+ dicom_data = pydicom.dcmread(dicom_files[selected_slice])
59
+
60
+ # Display the DICOM image
61
+ plt.imshow(dicom_data.pixel_array, cmap=plt.cm.bone)
62
  plt.axis("off")
63
  plt.title("DICOM Image")
64
  plt.tight_layout()
65
+ return plt
 
 
 
66
 
67
  if uploaded_zip_file is not None:
68
  try:
 
82
  dicom_files = [os.path.join(temp_dir, f) for f in os.listdir(temp_dir) if f.endswith(".dcm")]
83
  dicom_files.sort() # Sort the files
84
 
85
+ # if len(dicom_files) == 0:
86
+ # st.error("No DICOM files found in the ZIP archive.")
87
+ # else:
88
+ # # Display a slider for selecting the slice
89
+ # selected_slice = st.slider("Select a slice", 0, len(dicom_files) - 1, 0)
 
 
 
 
 
 
 
 
 
90
 
91
+ # # Display the DICOM image using the cached function
92
+ # plt = display_dicom_image(selected_slice, dicom_files)
93
+ # st.pyplot(plt)
94
 
95
  except Exception as e:
96
  st.error(f"Error: {str(e)}")