AdritRao commited on
Commit
8c3b194
·
1 Parent(s): d43df30

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -41
app.py CHANGED
@@ -73,54 +73,58 @@ if st.button("Analyze"):
73
  except subprocess.CalledProcessError as e:
74
  print(f"Error while running the script: {e}")
75
 
76
- command = "chmod +x inference.sh"
77
-
78
- try:
79
- subprocess.run(command, shell=True, check=True)
80
- print("Script 'inference.sh' has started running.")
81
- except subprocess.CalledProcessError as e:
82
- print(f"Error while making the script executable: {e}")
83
-
84
- command = "./inference.sh"
85
-
86
- try:
87
- subprocess.run(command, shell=True, check=True)
88
- print("Script 'inference.sh' has started running.")
89
- except subprocess.CalledProcessError as e:
90
- print(f"Error while making the script executable: {e}")
91
-
92
- # Set the flag to indicate that subprocess commands have been executed
93
  subprocess_executed = True
94
 
95
- # Assuming the 'outputs' directory is located at "/home/user/app/C2C/comp2comp/outputs"
96
- outputs_directory = "/home/user/app/C2C/outputs"
97
-
98
- # Get a list of subdirectories inside the 'outputs' directory
99
- subdirectories = [subdir for subdir in os.listdir(outputs_directory)
100
- if os.path.isdir(os.path.join(outputs_directory, subdir))]
101
 
102
- # Use the first (or only) subdirectory, or None if there are no subdirectories
103
- first_subdirectory = subdirectories[0] if subdirectories else None
 
 
 
 
 
104
 
105
- if first_subdirectory:
106
- # Construct the paths to the video and image files inside the first subdirectory
107
- video_path = os.path.join(outputs_directory, first_subdirectory, "temp_dicom_dir/images/summary/aaa.mp4")
108
- image_path = os.path.join(outputs_directory, first_subdirectory, "temp_dicom_dir/images/summary/diameter_graph.png")
109
- largest_slice = os.path.join(outputs_directory, first_subdirectory, "temp_dicom_dir/images/summary/out.png")
 
 
 
 
 
 
 
 
 
 
 
 
110
 
111
- if os.path.exists(largest_slice):
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)
 
 
 
 
 
 
 
 
 
124
 
125
 
126
 
 
73
  except subprocess.CalledProcessError as e:
74
  print(f"Error while running the script: {e}")
75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  subprocess_executed = True
77
 
78
+ if subprocess_executed:
 
 
 
 
 
79
 
80
+ command = "chmod +x inference.sh"
81
+
82
+ try:
83
+ subprocess.run(command, shell=True, check=True)
84
+ print("Script 'inference.sh' has started running.")
85
+ except subprocess.CalledProcessError as e:
86
+ print(f"Error while making the script executable: {e}")
87
 
88
+ command = "./inference.sh"
89
+
90
+ try:
91
+ subprocess.run(command, shell=True, check=True)
92
+ print("Script 'inference.sh' has started running.")
93
+ except subprocess.CalledProcessError as e:
94
+ print(f"Error while making the script executable: {e}")
95
+
96
+ # Set the flag to indicate that subprocess commands have been executed
97
+ subprocess_executed = True
98
+
99
+ # Assuming the 'outputs' directory is located at "/home/user/app/C2C/comp2comp/outputs"
100
+ outputs_directory = "/home/user/app/C2C/outputs"
101
+
102
+ # Get a list of subdirectories inside the 'outputs' directory
103
+ subdirectories = [subdir for subdir in os.listdir(outputs_directory)
104
+ if os.path.isdir(os.path.join(outputs_directory, subdir))]
105
 
106
+ # Use the first (or only) subdirectory, or None if there are no subdirectories
107
+ first_subdirectory = subdirectories[0] if subdirectories else None
 
108
 
109
+ if first_subdirectory:
110
+ # Construct the paths to the video and image files inside the first subdirectory
111
+ video_path = os.path.join(outputs_directory, first_subdirectory, "temp_dicom_dir/images/summary/aaa.mp4")
112
+ image_path = os.path.join(outputs_directory, first_subdirectory, "temp_dicom_dir/images/summary/diameter_graph.png")
113
+ largest_slice = os.path.join(outputs_directory, first_subdirectory, "temp_dicom_dir/images/summary/out.png")
114
 
115
+ if os.path.exists(largest_slice):
116
+ st.title("Largest Slice")
117
+ st.image(largest_slice, use_column_width=True)
118
+
119
+ # Display the video generated by the inference script
120
+ if os.path.exists(video_path):
121
+ st.title("Video")
122
+ st.video(video_path, format="video/mp4")
123
+
124
+ # Display the image generated by the inference script
125
+ if os.path.exists(image_path):
126
+ st.title("Diameter Graph")
127
+ st.image(image_path, use_column_width=True)
128
 
129
 
130