Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,24 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
|
|
3 |
import zipfile
|
|
|
4 |
import subprocess
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
logo_image_path = '1.png'
|
7 |
|
8 |
st.image(logo_image_path, width=150)
|
9 |
st.title("Automated Abdominal Aortic Aneurysm Detection")
|
10 |
|
|
|
11 |
@st.cache_resource
|
12 |
def install_dependencies():
|
13 |
command = "chmod +x install.sh"
|
@@ -16,6 +27,7 @@ def install_dependencies():
|
|
16 |
command = "./install.sh"
|
17 |
subprocess.run(command, shell=True, check=True)
|
18 |
|
|
|
19 |
@st.cache_resource
|
20 |
def run_inference():
|
21 |
command = "chmod +x inference.sh"
|
@@ -41,48 +53,7 @@ def search_file(start_path, target_file):
|
|
41 |
return os.path.join(root, target_file)
|
42 |
return None
|
43 |
|
44 |
-
|
45 |
-
return os.path.abspath(os.path.join(base_path, "C2C/comp2comp/utils/../../outputs"))
|
46 |
-
|
47 |
-
def fetch_outputs():
|
48 |
-
outputs_base_path = resolve_path("/home/user/app")
|
49 |
-
if os.path.exists(outputs_base_path):
|
50 |
-
subdirectories = [subdir for subdir in os.listdir(outputs_base_path)
|
51 |
-
if os.path.isdir(os.path.join(outputs_base_path, subdir))]
|
52 |
-
|
53 |
-
first_subdirectory = subdirectories[0] if subdirectories else None
|
54 |
-
|
55 |
-
if first_subdirectory:
|
56 |
-
subdirectory_path = os.path.join(outputs_base_path, first_subdirectory)
|
57 |
-
temp_dicom_dir_path = os.path.join(subdirectory_path, "temp_dicom_dir")
|
58 |
-
|
59 |
-
for root, dirs, _ in os.walk(temp_dicom_dir_path):
|
60 |
-
for subdir in dirs:
|
61 |
-
dicom_folder_path = os.path.join(root, subdir)
|
62 |
-
video_path = search_file(dicom_folder_path, "aaa.mp4")
|
63 |
-
if video_path: # Use this folder if it contains the mp4 file
|
64 |
-
image_path = search_file(dicom_folder_path, "diameter_graph.png")
|
65 |
-
largest_slice = search_file(dicom_folder_path, "out.png")
|
66 |
-
|
67 |
-
if video_path and image_path and largest_slice:
|
68 |
-
zip_filename = os.path.join("/home/user/app/C2C/temp_dicom_dir", "outputs.zip")
|
69 |
-
zip_and_download(dicom_folder_path, zip_filename)
|
70 |
-
|
71 |
-
st.title("Largest Slice")
|
72 |
-
st.image(largest_slice, use_column_width=True)
|
73 |
-
|
74 |
-
st.title("Video")
|
75 |
-
st.video(video_path, format="video/mp4")
|
76 |
-
|
77 |
-
st.title("Diameter Graph")
|
78 |
-
st.image(image_path, use_column_width=True)
|
79 |
-
return
|
80 |
-
st.error("Output files not found in any subdirectory")
|
81 |
-
else:
|
82 |
-
st.warning("Output files not found")
|
83 |
-
else:
|
84 |
-
st.error("Output directory not found")
|
85 |
-
|
86 |
def main():
|
87 |
st.write("Upload a ZIP file containing DICOM slices")
|
88 |
uploaded_zip_file = st.file_uploader("Upload a .zip file", type=["zip"])
|
@@ -103,10 +74,42 @@ def main():
|
|
103 |
st.success("Analysis started (expected time: 5 mins)")
|
104 |
run_inference()
|
105 |
|
106 |
-
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
except Exception as e:
|
109 |
st.error(f"Error: {str(e)}")
|
110 |
|
111 |
if __name__ == "__main__":
|
112 |
-
main()
|
|
|
1 |
import streamlit as st
|
2 |
+
import pydicom
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
import zipfile
|
5 |
+
import os
|
6 |
import subprocess
|
7 |
+
from datetime import datetime
|
8 |
+
import shutil
|
9 |
+
import moviepy.video.io.ImageSequenceClip
|
10 |
+
from io import BytesIO
|
11 |
+
from tkinter import Tcl
|
12 |
+
from PIL import Image
|
13 |
+
|
14 |
+
subprocess_executed = False
|
15 |
|
16 |
logo_image_path = '1.png'
|
17 |
|
18 |
st.image(logo_image_path, width=150)
|
19 |
st.title("Automated Abdominal Aortic Aneurysm Detection")
|
20 |
|
21 |
+
# Function to install dependencies
|
22 |
@st.cache_resource
|
23 |
def install_dependencies():
|
24 |
command = "chmod +x install.sh"
|
|
|
27 |
command = "./install.sh"
|
28 |
subprocess.run(command, shell=True, check=True)
|
29 |
|
30 |
+
# Function to run inference
|
31 |
@st.cache_resource
|
32 |
def run_inference():
|
33 |
command = "chmod +x inference.sh"
|
|
|
53 |
return os.path.join(root, target_file)
|
54 |
return None
|
55 |
|
56 |
+
# Main Streamlit code
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
def main():
|
58 |
st.write("Upload a ZIP file containing DICOM slices")
|
59 |
uploaded_zip_file = st.file_uploader("Upload a .zip file", type=["zip"])
|
|
|
74 |
st.success("Analysis started (expected time: 5 mins)")
|
75 |
run_inference()
|
76 |
|
77 |
+
outputs_directory = "/home/user/app/C2C/outputs"
|
78 |
+
|
79 |
+
if os.path.exists(outputs_directory):
|
80 |
+
subdirectories = [subdir for subdir in os.listdir(outputs_directory)
|
81 |
+
if os.path.isdir(os.path.join(outputs_directory, subdir))]
|
82 |
+
|
83 |
+
first_subdirectory = subdirectories[0] if subdirectories else None
|
84 |
+
|
85 |
+
if first_subdirectory:
|
86 |
+
subdirectory_path = os.path.join(outputs_directory, first_subdirectory)
|
87 |
+
temp_dicom_dir_path = os.path.join(subdirectory_path, "temp_dicom_dir")
|
88 |
+
|
89 |
+
video_path = search_file(temp_dicom_dir_path, "aaa.mp4")
|
90 |
+
image_path = search_file(temp_dicom_dir_path, "diameter_graph.png")
|
91 |
+
largest_slice = search_file(temp_dicom_dir_path, "out.png")
|
92 |
+
|
93 |
+
if video_path and image_path and largest_slice:
|
94 |
+
zip_filename = os.path.join(temp_dir, "outputs.zip")
|
95 |
+
zip_and_download(temp_dicom_dir_path, zip_filename)
|
96 |
+
|
97 |
+
st.title("Largest Slice")
|
98 |
+
st.image(largest_slice, use_column_width=True)
|
99 |
+
|
100 |
+
st.title("Video")
|
101 |
+
st.video(video_path, format="video/mp4")
|
102 |
+
|
103 |
+
st.title("Diameter Graph")
|
104 |
+
st.image(image_path, use_column_width=True)
|
105 |
+
else:
|
106 |
+
st.error("Output files not found")
|
107 |
+
else:
|
108 |
+
st.warning("Ouput files not found")
|
109 |
+
else:
|
110 |
+
st.error("Output files not found")
|
111 |
except Exception as e:
|
112 |
st.error(f"Error: {str(e)}")
|
113 |
|
114 |
if __name__ == "__main__":
|
115 |
+
main()
|