Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,13 +11,14 @@ import shutil
|
|
11 |
subprocess_executed = False
|
12 |
|
13 |
# Streamlit app title
|
14 |
-
st.
|
|
|
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 |
|
@@ -28,31 +29,33 @@ def display_dicom_image(selected_slice, dicom_files):
|
|
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)
|
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)
|
@@ -75,6 +78,34 @@ if uploaded_zip_file is not None:
|
|
75 |
st.error(f"Error: {str(e)}")
|
76 |
|
77 |
if st.button("Analyze"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
command = "chmod +x inference.sh"
|
79 |
|
80 |
try:
|
@@ -131,4 +162,3 @@ if st.button("Analyze"):
|
|
131 |
# finally:
|
132 |
# shutil.rmtree(temp_dir)
|
133 |
|
134 |
-
st.write("Upload a ZIP file containing DICOM slices to view the images.")
|
|
|
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 |
|
|
|
29 |
plt.tight_layout()
|
30 |
return plt
|
31 |
|
32 |
+
def execute_command_with_progress(command, description):
|
33 |
+
st.write(description)
|
34 |
+
process = subprocess.Popen(
|
35 |
+
command,
|
36 |
+
shell=True,
|
37 |
+
stdout=subprocess.PIPE,
|
38 |
+
stderr=subprocess.STDOUT,
|
39 |
+
universal_newlines=True,
|
40 |
+
bufsize=1,
|
41 |
+
)
|
42 |
+
|
43 |
+
for line in process.stdout:
|
44 |
+
st.text(line) # Display the output
|
45 |
+
# Assuming that the script provides a numeric progress value
|
46 |
+
try:
|
47 |
+
progress = float(line.strip()) # Extract a numeric progress value
|
48 |
+
st.progress(progress)
|
49 |
+
except ValueError:
|
50 |
+
pass
|
51 |
+
|
52 |
+
process.wait()
|
53 |
+
st.write(f"{description} has finished.")
|
54 |
+
|
55 |
if uploaded_zip_file is not None:
|
56 |
try:
|
57 |
# Create a temporary directory to unzip the files
|
58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
with zipfile.ZipFile(uploaded_zip_file, "r") as zip_ref:
|
61 |
zip_ref.extractall(temp_dir)
|
|
|
78 |
st.error(f"Error: {str(e)}")
|
79 |
|
80 |
if st.button("Analyze"):
|
81 |
+
|
82 |
+
command = "chmod +x install.sh"
|
83 |
+
try:
|
84 |
+
subprocess.run(command, shell=True, check=True)
|
85 |
+
print("Script 'install.sh' has been made executable.")
|
86 |
+
except subprocess.CalledProcessError as e:
|
87 |
+
print(f"Error while making the script executable: {e}")
|
88 |
+
|
89 |
+
command = "./install.sh"
|
90 |
+
try:
|
91 |
+
subprocess.run(command, shell=True, check=True)
|
92 |
+
print("Script 'install.sh' has started running.")
|
93 |
+
except subprocess.CalledProcessError as e:
|
94 |
+
print(f"Error while running the script: {e}")
|
95 |
+
|
96 |
+
temp_dir = "/home/user/app/C2C/temp_dicom_dir"
|
97 |
+
|
98 |
+
os.makedirs(temp_dir, exist_ok=True)
|
99 |
+
full_path = os.path.abspath(temp_dir)
|
100 |
+
|
101 |
+
try:
|
102 |
+
execute_command_with_progress(command, "Installing required C2C packages")
|
103 |
+
except subprocess.CalledProcessError as e:
|
104 |
+
st.error(f"Error while making the script executable: {e}")
|
105 |
+
|
106 |
+
|
107 |
+
|
108 |
+
|
109 |
command = "chmod +x inference.sh"
|
110 |
|
111 |
try:
|
|
|
162 |
# finally:
|
163 |
# shutil.rmtree(temp_dir)
|
164 |
|
|