AdritRao commited on
Commit
b531d2e
·
1 Parent(s): d525e10

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -25
app.py CHANGED
@@ -15,24 +15,11 @@ st.title("DICOM Image Viewer")
15
 
16
  # Upload a ZIP file containing DICOM slices
17
  uploaded_zip_file = st.file_uploader("Upload a ZIP file containing DICOM slices", type=["zip"])
 
18
 
19
- # Function to read and display the DICOM image
20
- @st.cache(suppress_st_warning=True, show_spinner=False)
21
- def display_dicom_image(selected_slice, dicom_files):
22
- dicom_data = pydicom.dcmread(dicom_files[selected_slice])
23
-
24
- # Display the DICOM image
25
- plt.imshow(dicom_data.pixel_array, cmap=plt.cm.bone)
26
- plt.axis("off")
27
- plt.title("DICOM Image")
28
- plt.tight_layout()
29
- return plt
30
-
31
- if uploaded_zip_file is not None:
32
- try:
33
- # Create a temporary directory to unzip the files
34
-
35
-
36
  command = "chmod +x install.sh"
37
  try:
38
  subprocess.run(command, shell=True, check=True)
@@ -44,8 +31,25 @@ if uploaded_zip_file is not None:
44
  try:
45
  subprocess.run(command, shell=True, check=True)
46
  print("Script 'install.sh' has started running.")
 
47
  except subprocess.CalledProcessError as e:
48
  print(f"Error while running the script: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
  temp_dir = "/home/user/app/C2C/temp_dicom_dir"
51
 
@@ -70,9 +74,11 @@ if uploaded_zip_file is not None:
70
  # Display the DICOM image using the cached function
71
  plt = display_dicom_image(selected_slice, dicom_files)
72
  st.pyplot(plt)
 
 
 
73
 
74
- if not subprocess_executed:
75
-
76
  command = "chmod +x inference.sh"
77
 
78
  try:
@@ -124,12 +130,6 @@ if uploaded_zip_file is not None:
124
  else:
125
  st.warning("No subdirectories or folders found inside the 'outputs' directory.")
126
 
127
-
128
-
129
-
130
- except Exception as e:
131
- st.error(f"Error: {str(e)}")
132
  # finally:
133
  # shutil.rmtree(temp_dir)
134
 
135
- st.write("Upload a ZIP file containing DICOM slices to view the images.")
 
15
 
16
  # Upload a ZIP file containing DICOM slices
17
  uploaded_zip_file = st.file_uploader("Upload a ZIP file containing DICOM slices", type=["zip"])
18
+ st.write("Upload a ZIP file containing DICOM slices to view the images.")
19
 
20
+ @st.cache_resource
21
+ def install_dependencies():
22
+ if not install_script_executed:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  command = "chmod +x install.sh"
24
  try:
25
  subprocess.run(command, shell=True, check=True)
 
31
  try:
32
  subprocess.run(command, shell=True, check=True)
33
  print("Script 'install.sh' has started running.")
34
+ install_script_executed = True
35
  except subprocess.CalledProcessError as e:
36
  print(f"Error while running the script: {e}")
37
+
38
+ # Function to read and display the DICOM image
39
+ @st.cache_resource
40
+ def display_dicom_image(selected_slice, dicom_files):
41
+ dicom_data = pydicom.dcmread(dicom_files[selected_slice])
42
+
43
+ # Display the DICOM image
44
+ plt.imshow(dicom_data.pixel_array, cmap=plt.cm.bone)
45
+ plt.axis("off")
46
+ plt.title("DICOM Image")
47
+ plt.tight_layout()
48
+ return plt
49
+
50
+ if uploaded_zip_file is not None:
51
+ try:
52
+ install_dependencies()
53
 
54
  temp_dir = "/home/user/app/C2C/temp_dicom_dir"
55
 
 
74
  # Display the DICOM image using the cached function
75
  plt = display_dicom_image(selected_slice, dicom_files)
76
  st.pyplot(plt)
77
+
78
+ except Exception as e:
79
+ st.error(f"Error: {str(e)}")
80
 
81
+ if st.button("Analyze"):
 
82
  command = "chmod +x inference.sh"
83
 
84
  try:
 
130
  else:
131
  st.warning("No subdirectories or folders found inside the 'outputs' directory.")
132
 
 
 
 
 
 
133
  # finally:
134
  # shutil.rmtree(temp_dir)
135