Spaces:
Sleeping
Sleeping
File size: 5,011 Bytes
3318510 e9f7fd2 affc586 3eb11cb e665ab2 5253012 94e3d42 84f200a e6e540c ebc7a7f 747d9f4 9eed4fa b531d2e e6e540c b531d2e b3c4662 e6e540c b3c4662 b531d2e e6e540c 7a0b4da e6e540c 3281da3 60f23bc 807f381 057ede6 807f381 d17c251 e6e540c 94985b8 e6e540c b531d2e 807f381 b531d2e 9eed4fa 36ee72b e6e540c ff4d8cd 36ee72b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
import streamlit as st
import pydicom
import zipfile
import os
import subprocess
subprocess_executed = False
logo_image_path = '1.png'
st.image(logo_image_path, width=150)
st.title("Automated Abdominal Aortic Aneurysm Detection")
st.write("Upload a ZIP file containing DICOM slices")
uploaded_zip_file = st.file_uploader("Upload a .zip file", type=["zip"])
@st.cache_resource
def install_dependencies():
command = "chmod +x install.sh"
try:
subprocess.run(command, shell=True, check=True)
except subprocess.CalledProcessError as e:
pass
command = "./install.sh"
try:
subprocess.run(command, shell=True, check=True)
except subprocess.CalledProcessError as e:
pass
@st.cache_resource
def run_inference():
command = "chmod +x inference.sh"
try:
subprocess.run(command, shell=True, check=True)
except subprocess.CalledProcessError as e:
pass
command = "./inference.sh"
try:
subprocess.run(command, shell=True, check=True)
except subprocess.CalledProcessError as e:
pass
def create_zip_file():
outputs_directory = "/home/user/app/C2C/outputs"
subdirectories = [subdir for subdir in os.listdir(outputs_directory)
if os.path.isdir(os.path.join(outputs_directory, subdir))]
first_subdirectory = subdirectories[0] if subdirectories else None
if first_subdirectory:
subdirectory_path = os.path.join(outputs_directory, first_subdirectory)
temp_dicom_dir_path = os.path.join(subdirectory_path, "temp_dicom_dir")
largest_slice = os.path.join(temp_dicom_dir_path, "largest_slice.png")
diameter_graph = os.path.join(temp_dicom_dir_path, "diameter_graph.png")
video_path = os.path.join(temp_dicom_dir_path, "video.mp4")
files_to_zip = [largest_slice, diameter_graph, video_path]
zip_file_path = os.path.join(outputs_directory, "outputs.zip")
with zipfile.ZipFile(zip_file_path, 'w') as zipf:
for file in files_to_zip:
zipf.write(file, os.path.basename(file))
return zip_file_path
else:
return None
if uploaded_zip_file is not None:
try:
install_dependencies()
temp_dir = "/home/user/app/C2C/temp_dicom_dir"
os.makedirs(temp_dir, exist_ok=True)
with zipfile.ZipFile(uploaded_zip_file, "r") as zip_ref:
zip_ref.extractall(temp_dir)
dicom_files = [os.path.join(temp_dir, f) for f in os.listdir(temp_dir) if f.endswith(".dcm")]
dicom_files.sort()
for file_path in dicom_files:
ds = pydicom.dcmread(file_path)
if 'PatientName' in ds:
ds.PatientName = 'Anonymized'
if 'PatientID' in ds:
ds.PatientID = '00000000'
ds.save_as(file_path)
except Exception as e:
st.error(f"Error: {str(e)}")
if st.button("Analyze"):
st.success("Analysis started (expected time: 5 mins)")
run_inference()
outputs_directory = "/home/user/app/C2C/outputs"
zip_file_path = create_zip_file()
if zip_file_path:
st.success("Analysis completed. Click the button below to download the outputs.")
st.download_button(label="Download Outputs", data=zip_file_path, file_name="outputs.zip", mime="application/zip")
subdirectories = [subdir for subdir in os.listdir(outputs_directory)
if os.path.isdir(os.path.join(outputs_directory, subdir))]
first_subdirectory = subdirectories[0] if subdirectories else None
if first_subdirectory:
subdirectory_path = os.path.join(outputs_directory, first_subdirectory)
temp_dicom_dir_path = os.path.join(subdirectory_path, "temp_dicom_dir")
dicom_subdirectories = [subdir for subdir in os.listdir(temp_dicom_dir_path)
if os.path.isdir(os.path.join(temp_dicom_dir_path, subdir))]
first_dicom_subdirectory = dicom_subdirectories[0] if dicom_subdirectories else None
if first_dicom_subdirectory:
video_path = os.path.join(temp_dicom_dir_path, first_dicom_subdirectory, "images/summary/aaa.mp4")
image_path = os.path.join(temp_dicom_dir_path, first_dicom_subdirectory, "images/summary/diameter_graph.png")
largest_slice = os.path.join(temp_dicom_dir_path, first_dicom_subdirectory, "images/summary/out.png")
if os.path.exists(largest_slice):
st.title("Largest Slice")
st.image(largest_slice, use_column_width=True)
if os.path.exists(video_path):
st.title("Video")
st.video(video_path, format="video/mp4")
if os.path.exists(image_path):
st.title("Diameter Graph")
st.image(image_path, use_column_width=True)
else:
st.warning("No subdirectories or folders found inside 'temp_dicom_dir'.")
else:
st.warning("No subdirectories or folders found inside the 'outputs' directory.")
|