Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -51,6 +51,51 @@ def search_file(start_path, target_file):
|
|
| 51 |
return os.path.join(root, target_file)
|
| 52 |
return None
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
def main():
|
| 55 |
st.write("Upload a ZIP file containing DICOM slices")
|
| 56 |
uploaded_zip_file = st.file_uploader("Upload a .zip file", type=["zip"])
|
|
@@ -71,49 +116,8 @@ def main():
|
|
| 71 |
st.success("Analysis started (expected time: 5 mins)")
|
| 72 |
run_inference()
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
if os.path.exists(outputs_directory):
|
| 77 |
-
subdirectories = [subdir for subdir in os.listdir(outputs_directory)
|
| 78 |
-
if os.path.isdir(os.path.join(outputs_directory, subdir))]
|
| 79 |
-
|
| 80 |
-
first_subdirectory = subdirectories[0] if subdirectories else None
|
| 81 |
-
|
| 82 |
-
if first_subdirectory:
|
| 83 |
-
subdirectory_path = os.path.join(outputs_directory, first_subdirectory)
|
| 84 |
-
temp_dicom_dir_path = os.path.join(subdirectory_path, "temp_dicom_dir")
|
| 85 |
-
|
| 86 |
-
dicom_subdirectories = [subdir for subdir in os.listdir(temp_dicom_dir_path)
|
| 87 |
-
if os.path.isdir(os.path.join(temp_dicom_dir_path, subdir))]
|
| 88 |
-
|
| 89 |
-
dicom_folder = dicom_subdirectories[0] if dicom_subdirectories else None
|
| 90 |
-
|
| 91 |
-
if dicom_folder:
|
| 92 |
-
dicom_folder_path = os.path.join(temp_dicom_dir_path, dicom_folder)
|
| 93 |
-
video_path = search_file(dicom_folder_path, "aaa.mp4")
|
| 94 |
-
image_path = search_file(dicom_folder_path, "diameter_graph.png")
|
| 95 |
-
largest_slice = search_file(dicom_folder_path, "out.png")
|
| 96 |
-
|
| 97 |
-
if video_path and image_path and largest_slice:
|
| 98 |
-
zip_filename = os.path.join(temp_dir, "outputs.zip")
|
| 99 |
-
zip_and_download(dicom_folder_path, zip_filename)
|
| 100 |
-
|
| 101 |
-
st.title("Largest Slice")
|
| 102 |
-
st.image(largest_slice, use_column_width=True)
|
| 103 |
-
|
| 104 |
-
st.title("Video")
|
| 105 |
-
st.video(video_path, format="video/mp4")
|
| 106 |
-
|
| 107 |
-
st.title("Diameter Graph")
|
| 108 |
-
st.image(image_path, use_column_width=True)
|
| 109 |
-
else:
|
| 110 |
-
st.error("Output files not found")
|
| 111 |
-
else:
|
| 112 |
-
st.error("DICOM folder not found")
|
| 113 |
-
else:
|
| 114 |
-
st.warning("Output files not found")
|
| 115 |
-
else:
|
| 116 |
-
st.error("Output files not found")
|
| 117 |
except Exception as e:
|
| 118 |
st.error(f"Error: {str(e)}")
|
| 119 |
|
|
|
|
| 51 |
return os.path.join(root, target_file)
|
| 52 |
return None
|
| 53 |
|
| 54 |
+
def fetch_outputs():
|
| 55 |
+
outputs_directory = "/home/user/app/C2C/outputs"
|
| 56 |
+
|
| 57 |
+
if os.path.exists(outputs_directory):
|
| 58 |
+
subdirectories = [subdir for subdir in os.listdir(outputs_directory)
|
| 59 |
+
if os.path.isdir(os.path.join(outputs_directory, subdir))]
|
| 60 |
+
|
| 61 |
+
first_subdirectory = subdirectories[0] if subdirectories else None
|
| 62 |
+
|
| 63 |
+
if first_subdirectory:
|
| 64 |
+
subdirectory_path = os.path.join(outputs_directory, first_subdirectory)
|
| 65 |
+
temp_dicom_dir_path = os.path.join(subdirectory_path, "temp_dicom_dir")
|
| 66 |
+
|
| 67 |
+
dicom_subdirectories = [subdir for subdir in os.listdir(temp_dicom_dir_path)
|
| 68 |
+
if os.path.isdir(os.path.join(temp_dicom_dir_path, subdir))]
|
| 69 |
+
|
| 70 |
+
dicom_folder = dicom_subdirectories[0] if dicom_subdirectories else None
|
| 71 |
+
|
| 72 |
+
if dicom_folder:
|
| 73 |
+
dicom_folder_path = os.path.join(temp_dicom_dir_path, dicom_folder)
|
| 74 |
+
video_path = search_file(dicom_folder_path, "aaa.mp4")
|
| 75 |
+
image_path = search_file(dicom_folder_path, "diameter_graph.png")
|
| 76 |
+
largest_slice = search_file(dicom_folder_path, "out.png")
|
| 77 |
+
|
| 78 |
+
if video_path and image_path and largest_slice:
|
| 79 |
+
zip_filename = os.path.join("/home/user/app/C2C/temp_dicom_dir", "outputs.zip")
|
| 80 |
+
zip_and_download(dicom_folder_path, zip_filename)
|
| 81 |
+
|
| 82 |
+
st.title("Largest Slice")
|
| 83 |
+
st.image(largest_slice, use_column_width=True)
|
| 84 |
+
|
| 85 |
+
st.title("Video")
|
| 86 |
+
st.video(video_path, format="video/mp4")
|
| 87 |
+
|
| 88 |
+
st.title("Diameter Graph")
|
| 89 |
+
st.image(image_path, use_column_width=True)
|
| 90 |
+
else:
|
| 91 |
+
st.error("Output files not found")
|
| 92 |
+
else:
|
| 93 |
+
st.error("DICOM folder not found")
|
| 94 |
+
else:
|
| 95 |
+
st.warning("Output files not found")
|
| 96 |
+
else:
|
| 97 |
+
st.error("Output files not found")
|
| 98 |
+
|
| 99 |
def main():
|
| 100 |
st.write("Upload a ZIP file containing DICOM slices")
|
| 101 |
uploaded_zip_file = st.file_uploader("Upload a .zip file", type=["zip"])
|
|
|
|
| 116 |
st.success("Analysis started (expected time: 5 mins)")
|
| 117 |
run_inference()
|
| 118 |
|
| 119 |
+
if st.button("Fetch Outputs"):
|
| 120 |
+
fetch_outputs()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
except Exception as e:
|
| 122 |
st.error(f"Error: {str(e)}")
|
| 123 |
|