AdritRao commited on
Commit
94e3d42
1 Parent(s): a760893

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -35
app.py CHANGED
@@ -5,24 +5,8 @@ import zipfile
5
  import os
6
  import subprocess
7
 
8
- import subprocess
9
-
10
- # Command to make the script executable
11
- command = "chmod +x install.sh"
12
-
13
- try:
14
- subprocess.run(command, shell=True, check=True)
15
- print("Script 'install.sh' has been made executable.")
16
- except subprocess.CalledProcessError as e:
17
- print(f"Error while making the script executable: {e}")
18
-
19
- command = "./install.sh"
20
-
21
- try:
22
- subprocess.run(command, shell=True, check=True)
23
- print("Script 'install.sh' has been made executable.")
24
- except subprocess.CalledProcessError as e:
25
- print(f"Error while making the script executable: {e}")
26
 
27
  # Streamlit app title
28
  st.title("DICOM Image Viewer")
@@ -50,6 +34,24 @@ if uploaded_zip_file is not None:
50
 
51
  st.write(f"Temporary directory path: {temp_dir}")
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
  with zipfile.ZipFile(uploaded_zip_file, "r") as zip_ref:
55
  zip_ref.extractall(temp_dir)
@@ -58,22 +60,6 @@ if uploaded_zip_file is not None:
58
  dicom_files = [os.path.join(temp_dir, f) for f in os.listdir(temp_dir) if f.endswith(".dcm")]
59
  dicom_files.sort() # Sort the files
60
 
61
- command = "chmod +x inference.sh"
62
-
63
- try:
64
- subprocess.run(command, shell=True, check=True)
65
- print("Script 'inference.sh' has started running.")
66
- except subprocess.CalledProcessError as e:
67
- print(f"Error while making the script executable: {e}")
68
-
69
- command = "./inference.sh"
70
-
71
- try:
72
- subprocess.run(command, shell=True, check=True)
73
- print("Script 'inference.sh' has started running.")
74
- except subprocess.CalledProcessError as e:
75
- print(f"Error while making the script executable: {e}")
76
-
77
  if len(dicom_files) == 0:
78
  st.error("No DICOM files found in the ZIP archive.")
79
  else:
@@ -92,4 +78,4 @@ if uploaded_zip_file is not None:
92
  os.remove(file)
93
  os.rmdir(temp_dir)
94
 
95
- st.write("Upload a ZIP file containing DICOM slices to view the images.")
 
5
  import os
6
  import subprocess
7
 
8
+ # Flag to track if subprocess commands have been executed
9
+ subprocess_executed = False
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  # Streamlit app title
12
  st.title("DICOM Image Viewer")
 
34
 
35
  st.write(f"Temporary directory path: {temp_dir}")
36
 
37
+ if not subprocess_executed:
38
+ # Execute the subprocess commands only once
39
+ command = "chmod +x install.sh"
40
+ try:
41
+ subprocess.run(command, shell=True, check=True)
42
+ print("Script 'install.sh' has been made executable.")
43
+ except subprocess.CalledProcessError as e:
44
+ print(f"Error while making the script executable: {e}")
45
+
46
+ command = "./install.sh"
47
+ try:
48
+ subprocess.run(command, shell=True, check=True)
49
+ print("Script 'install.sh' has started running.")
50
+ except subprocess.CalledProcessError as e:
51
+ print(f"Error while running the script: {e}")
52
+
53
+ # Set the flag to indicate that subprocess commands have been executed
54
+ subprocess_executed = True
55
 
56
  with zipfile.ZipFile(uploaded_zip_file, "r") as zip_ref:
57
  zip_ref.extractall(temp_dir)
 
60
  dicom_files = [os.path.join(temp_dir, f) for f in os.listdir(temp_dir) if f.endswith(".dcm")]
61
  dicom_files.sort() # Sort the files
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  if len(dicom_files) == 0:
64
  st.error("No DICOM files found in the ZIP archive.")
65
  else:
 
78
  os.remove(file)
79
  os.rmdir(temp_dir)
80
 
81
+ st.write("Upload a ZIP file containing DICOM slices to view the images.")