AdritRao commited on
Commit
b8b9be3
·
1 Parent(s): d17c251

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -37
app.py CHANGED
@@ -54,21 +54,6 @@ def run_inference():
54
  except subprocess.CalledProcessError as e:
55
  print(f"Error while running the script: {e}")
56
 
57
- # Function to read and display the DICOM image
58
- def convert_dicom_to_png(dicom_data, output_dir, index):
59
- # Convert DICOM to a PNG image
60
- plt.imshow(dicom_data.pixel_array, cmap=plt.cm.bone)
61
- plt.axis("off")
62
- plt.title("DICOM Image")
63
- plt.tight_layout()
64
- img_buffer = BytesIO()
65
- plt.savefig(img_buffer, format="png")
66
- img_buffer.seek(0)
67
- output_path = os.path.join(output_dir, f"image_{index:03d}.png")
68
- with open(output_path, "wb") as f:
69
- f.write(img_buffer.read())
70
- return output_path
71
-
72
  if uploaded_zip_file is not None:
73
  try:
74
  install_dependencies()
@@ -88,28 +73,6 @@ if uploaded_zip_file is not None:
88
  # Get a list of DICOM files in the directory
89
  dicom_files = [os.path.join(temp_dir, f) for f in os.listdir(temp_dir) if f.endswith(".dcm")]
90
  dicom_files.sort() # Sort the files
91
-
92
- if len(dicom_files) == 0:
93
- st.error("No DICOM files found in the ZIP archive.")
94
- else:
95
- # Convert DICOM slices to PNG frames and save them to the output folder
96
- for i, dicom_file in enumerate(dicom_files):
97
- dicom_data = pydicom.dcmread(dicom_file)
98
- convert_dicom_to_png(dicom_data, output_image_dir, i)
99
-
100
- image_folder = output_image_dir
101
- fps = 20
102
- image_files = [
103
- os.path.join(image_folder, img)
104
- for img in Tcl().call("lsort", "-dict", os.listdir(image_folder))
105
- if img.endswith(".png")
106
- ]
107
- clip = moviepy.video.io.ImageSequenceClip.ImageSequenceClip(
108
- image_files, fps=fps
109
- )
110
- clip.write_videofile("aaa.mp4")
111
-
112
- st.video("aaa.mp4", format="video/mp4")
113
 
114
  except Exception as e:
115
  st.error(f"Error: {str(e)}")
 
54
  except subprocess.CalledProcessError as e:
55
  print(f"Error while running the script: {e}")
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  if uploaded_zip_file is not None:
58
  try:
59
  install_dependencies()
 
73
  # Get a list of DICOM files in the directory
74
  dicom_files = [os.path.join(temp_dir, f) for f in os.listdir(temp_dir) if f.endswith(".dcm")]
75
  dicom_files.sort() # Sort the files
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
 
77
  except Exception as e:
78
  st.error(f"Error: {str(e)}")