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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -55
app.py CHANGED
@@ -11,14 +11,13 @@ import shutil
11
  subprocess_executed = False
12
 
13
  # Streamlit app title
14
- st.markdown("<h1 style='text-align: center;'>A<sup>4</sup></h1>", unsafe_allow_html=True)
15
- st.subheader("Automated AAA Diameter Measurements")
16
 
17
  # Upload a ZIP file containing DICOM slices
18
  uploaded_zip_file = st.file_uploader("Upload a ZIP file containing DICOM slices", type=["zip"])
19
- st.write("Upload a ZIP file containing DICOM slices to view the images.")
20
 
21
  # Function to read and display the DICOM image
 
22
  def display_dicom_image(selected_slice, dicom_files):
23
  dicom_data = pydicom.dcmread(dicom_files[selected_slice])
24
 
@@ -32,10 +31,28 @@ def display_dicom_image(selected_slice, dicom_files):
32
  if uploaded_zip_file is not None:
33
  try:
34
  # Create a temporary directory to unzip the files
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  temp_dir = "/home/user/app/C2C/temp_dicom_dir"
36
 
37
  os.makedirs(temp_dir, exist_ok=True)
38
  full_path = os.path.abspath(temp_dir)
 
 
39
 
40
  with zipfile.ZipFile(uploaded_zip_file, "r") as zip_ref:
41
  zip_ref.extractall(temp_dir)
@@ -54,68 +71,65 @@ if uploaded_zip_file is not None:
54
  plt = display_dicom_image(selected_slice, dicom_files)
55
  st.pyplot(plt)
56
 
57
- except Exception as e:
58
- st.error(f"Error: {str(e)}")
59
-
60
- if st.button("Analyze"):
61
 
62
- subprocess_executed = True
63
-
64
- if subprocess_executed:
65
-
66
- command = "chmod +x install.sh"
67
-
68
- try:
69
- subprocess.run(command, shell=True, check=True)
70
- print("Script 'inference.sh' has started running.")
71
- except subprocess.CalledProcessError as e:
72
- print(f"Error while making the script executable: {e}")
73
 
74
- command = "./install.sh"
 
 
 
 
75
 
76
- try:
77
- subprocess.run(command, shell=True, check=True)
78
- print("Script 'inference.sh' has started running.")
79
- except subprocess.CalledProcessError as e:
80
- print(f"Error while making the script executable: {e}")
81
-
82
- # Set the flag to indicate that subprocess commands have been executed
83
- subprocess_executed = True
84
-
85
- # Assuming the 'outputs' directory is located at "/home/user/app/C2C/comp2comp/outputs"
86
- outputs_directory = "/home/user/app/C2C/outputs"
87
-
88
- # Get a list of subdirectories inside the 'outputs' directory
89
- subdirectories = [subdir for subdir in os.listdir(outputs_directory)
90
- if os.path.isdir(os.path.join(outputs_directory, subdir))]
91
 
92
- # Use the first (or only) subdirectory, or None if there are no subdirectories
93
- first_subdirectory = subdirectories[0] if subdirectories else None
94
-
95
- if first_subdirectory:
96
- # Construct the paths to the video and image files inside the first subdirectory
97
- video_path = os.path.join(outputs_directory, first_subdirectory, "temp_dicom_dir/images/summary/aaa.mp4")
98
- image_path = os.path.join(outputs_directory, first_subdirectory, "temp_dicom_dir/images/summary/diameter_graph.png")
99
- largest_slice = os.path.join(outputs_directory, first_subdirectory, "temp_dicom_dir/images/summary/out.png")
100
-
101
- if os.path.exists(largest_slice):
102
- st.title("Largest Slice")
103
- st.image(largest_slice, use_column_width=True)
 
 
 
 
 
 
 
 
 
 
 
 
104
 
105
- # Display the video generated by the inference script
106
- if os.path.exists(video_path):
107
- st.title("Video")
108
- st.video(video_path, format="video/mp4")
 
 
 
 
109
 
110
- # Display the image generated by the inference script
111
- if os.path.exists(image_path):
112
- st.title("Diameter Graph")
113
- st.image(image_path, use_column_width=True)
 
 
114
 
115
 
116
 
117
 
118
-
 
119
  # finally:
120
  # shutil.rmtree(temp_dir)
121
 
 
 
11
  subprocess_executed = False
12
 
13
  # Streamlit app title
14
+ 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
 
 
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)
39
+ print("Script 'install.sh' has been made executable.")
40
+ except subprocess.CalledProcessError as e:
41
+ print(f"Error while making the script executable: {e}")
42
+
43
+ command = "./install.sh"
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
 
52
  os.makedirs(temp_dir, exist_ok=True)
53
  full_path = os.path.abspath(temp_dir)
54
+
55
+ st.write(f"Temporary directory path: {full_path}")
56
 
57
  with zipfile.ZipFile(uploaded_zip_file, "r") as zip_ref:
58
  zip_ref.extractall(temp_dir)
 
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:
79
+ subprocess.run(command, shell=True, check=True)
80
+ print("Script 'inference.sh' has started running.")
81
+ except subprocess.CalledProcessError as e:
82
+ print(f"Error while making the script executable: {e}")
83
 
84
+ command = "./inference.sh"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
+ try:
87
+ subprocess.run(command, shell=True, check=True)
88
+ print("Script 'inference.sh' has started running.")
89
+ except subprocess.CalledProcessError as e:
90
+ print(f"Error while making the script executable: {e}")
91
+
92
+ # Set the flag to indicate that subprocess commands have been executed
93
+ subprocess_executed = True
94
+
95
+ # Assuming the 'outputs' directory is located at "/home/user/app/C2C/comp2comp/outputs"
96
+ outputs_directory = "/home/user/app/C2C/outputs"
97
+
98
+ # Get a list of subdirectories inside the 'outputs' directory
99
+ subdirectories = [subdir for subdir in os.listdir(outputs_directory)
100
+ if os.path.isdir(os.path.join(outputs_directory, subdir))]
101
+
102
+ # Use the first (or only) subdirectory, or None if there are no subdirectories
103
+ first_subdirectory = subdirectories[0] if subdirectories else None
104
+
105
+ if first_subdirectory:
106
+ # Construct the paths to the video and image files inside the first subdirectory
107
+ video_path = os.path.join(outputs_directory, first_subdirectory, "temp_dicom_dir/images/summary/aaa.mp4")
108
+ image_path = os.path.join(outputs_directory, first_subdirectory, "temp_dicom_dir/images/summary/diameter_graph.png")
109
+ largest_slice = os.path.join(outputs_directory, first_subdirectory, "temp_dicom_dir/images/summary/out.png")
110
 
111
+ if os.path.exists(largest_slice):
112
+ st.title("Largest Slice")
113
+ st.image(largest_slice, use_column_width=True)
114
+
115
+ # Display the video generated by the inference script
116
+ if os.path.exists(video_path):
117
+ st.title("Video")
118
+ st.video(video_path, format="video/mp4")
119
 
120
+ # Display the image generated by the inference script
121
+ if os.path.exists(image_path):
122
+ st.title("Diameter Graph")
123
+ st.image(image_path, use_column_width=True)
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.")