AdritRao commited on
Commit
94985b8
·
verified ·
1 Parent(s): ebc7a7f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -9
app.py CHANGED
@@ -71,7 +71,21 @@ if uploaded_zip_file is not None:
71
  zip_ref.extractall(temp_dir)
72
 
73
  dicom_files = [os.path.join(temp_dir, f) for f in os.listdir(temp_dir) if f.endswith(".dcm")]
74
- dicom_files.sort() # Sort the files
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
76
  except Exception as e:
77
  st.error(f"Error: {str(e)}")
@@ -81,26 +95,20 @@ if st.button("Analyze"):
81
  st.success("Analysis started (expected time: 5 mins)")
82
  run_inference()
83
 
84
- # Assuming the 'outputs' directory is located at "/home/user/app/C2C/comp2comp/outputs"
85
  outputs_directory = "/home/user/app/C2C/outputs"
86
 
87
- # Get a list of subdirectories inside the 'outputs' directory
88
  subdirectories = [subdir for subdir in os.listdir(outputs_directory)
89
  if os.path.isdir(os.path.join(outputs_directory, subdir))]
90
 
91
- # Use the first (or only) subdirectory, or None if there are no subdirectories
92
  first_subdirectory = subdirectories[0] if subdirectories else None
93
 
94
  if first_subdirectory:
95
- # Construct the paths to the video and image files inside the first subdirectory
96
  subdirectory_path = os.path.join(outputs_directory, first_subdirectory)
97
  temp_dicom_dir_path = os.path.join(subdirectory_path, "temp_dicom_dir")
98
 
99
- # Get a list of subdirectories inside the 'temp_dicom_dir' directory
100
  dicom_subdirectories = [subdir for subdir in os.listdir(temp_dicom_dir_path)
101
  if os.path.isdir(os.path.join(temp_dicom_dir_path, subdir))]
102
 
103
- # Use the first (or only) subdirectory inside 'temp_dicom_dir', or None if there are none
104
  first_dicom_subdirectory = dicom_subdirectories[0] if dicom_subdirectories else None
105
 
106
  if first_dicom_subdirectory:
@@ -112,12 +120,12 @@ if st.button("Analyze"):
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)
 
71
  zip_ref.extractall(temp_dir)
72
 
73
  dicom_files = [os.path.join(temp_dir, f) for f in os.listdir(temp_dir) if f.endswith(".dcm")]
74
+ dicom_files.sort()
75
+
76
+ # Anonymize DICOM files
77
+ for file_path in dicom_files:
78
+ ds = pydicom.dcmread(file_path)
79
+
80
+ # Anonymize personal information
81
+ if 'PatientName' in ds:
82
+ ds.PatientName = 'Anonymized'
83
+ if 'PatientID' in ds:
84
+ ds.PatientID = '00000000'
85
+
86
+ print("Anonymized")
87
+
88
+ ds.save_as(file_path)
89
 
90
  except Exception as e:
91
  st.error(f"Error: {str(e)}")
 
95
  st.success("Analysis started (expected time: 5 mins)")
96
  run_inference()
97
 
 
98
  outputs_directory = "/home/user/app/C2C/outputs"
99
 
 
100
  subdirectories = [subdir for subdir in os.listdir(outputs_directory)
101
  if os.path.isdir(os.path.join(outputs_directory, subdir))]
102
 
 
103
  first_subdirectory = subdirectories[0] if subdirectories else None
104
 
105
  if first_subdirectory:
 
106
  subdirectory_path = os.path.join(outputs_directory, first_subdirectory)
107
  temp_dicom_dir_path = os.path.join(subdirectory_path, "temp_dicom_dir")
108
 
 
109
  dicom_subdirectories = [subdir for subdir in os.listdir(temp_dicom_dir_path)
110
  if os.path.isdir(os.path.join(temp_dicom_dir_path, subdir))]
111
 
 
112
  first_dicom_subdirectory = dicom_subdirectories[0] if dicom_subdirectories else None
113
 
114
  if first_dicom_subdirectory:
 
120
  st.title("Largest Slice")
121
  st.image(largest_slice, use_column_width=True)
122
 
123
+ # Display the video
124
  if os.path.exists(video_path):
125
  st.title("Video")
126
  st.video(video_path, format="video/mp4")
127
 
128
+ # Display the image
129
  if os.path.exists(image_path):
130
  st.title("Diameter Graph")
131
  st.image(image_path, use_column_width=True)