Sadjad Alikhani commited on
Commit
df7ce72
·
verified ·
1 Parent(s): 0c172d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -112,8 +112,10 @@ def plot_confusion_matrix(y_true, y_pred, title):
112
  plt.savefig(f"{title}.png")
113
  return Image.open(f"{title}.png")
114
 
115
- # Function to process the uploaded HDF5 file and perform classification using the custom model
116
- def process_hdf5_file(uploaded_file, percentage_idx):
 
 
117
  capture = PrintCapture()
118
  sys.stdout = capture # Redirect print statements to capture
119
 
@@ -127,14 +129,15 @@ def process_hdf5_file(uploaded_file, percentage_idx):
127
  subprocess.run(["git", "clone", model_repo_url, model_repo_dir], check=True)
128
 
129
  # Step 2: Verify the repository was cloned and change the working directory
130
- if os.path.exists(model_repo_dir):
131
- os.chdir(model_repo_dir)
 
132
  print(f"Changed working directory to {os.getcwd()}")
133
  print(f"Directory content: {os.listdir(os.getcwd())}") # Debugging: Check repo content
134
  else:
135
- print(f"Directory {model_repo_dir} does not exist.")
136
  return
137
-
138
  # Step 3: Dynamically load lwm_model.py, input_preprocess.py, and inference.py
139
  lwm_model_path = os.path.join(os.getcwd(), 'lwm_model.py')
140
  input_preprocess_path = os.path.join(os.getcwd(), 'input_preprocess.py')
@@ -181,6 +184,8 @@ def process_hdf5_file(uploaded_file, percentage_idx):
181
  return str(e), str(e), capture.get_output()
182
 
183
  finally:
 
 
184
  sys.stdout = sys.__stdout__ # Reset print statements
185
 
186
  # Function to handle logic based on whether a file is uploaded or not
 
112
  plt.savefig(f"{title}.png")
113
  return Image.open(f"{title}.png")
114
 
115
+ # Store the original working directory when the app starts
116
+ original_dir = os.getcwd()
117
+
118
+ def process_p_file(uploaded_file, percentage_idx, complexity_idx):
119
  capture = PrintCapture()
120
  sys.stdout = capture # Redirect print statements to capture
121
 
 
129
  subprocess.run(["git", "clone", model_repo_url, model_repo_dir], check=True)
130
 
131
  # Step 2: Verify the repository was cloned and change the working directory
132
+ repo_work_dir = os.path.join(original_dir, model_repo_dir)
133
+ if os.path.exists(repo_work_dir):
134
+ os.chdir(repo_work_dir) # Change the working directory only once
135
  print(f"Changed working directory to {os.getcwd()}")
136
  print(f"Directory content: {os.listdir(os.getcwd())}") # Debugging: Check repo content
137
  else:
138
+ print(f"Directory {repo_work_dir} does not exist.")
139
  return
140
+
141
  # Step 3: Dynamically load lwm_model.py, input_preprocess.py, and inference.py
142
  lwm_model_path = os.path.join(os.getcwd(), 'lwm_model.py')
143
  input_preprocess_path = os.path.join(os.getcwd(), 'input_preprocess.py')
 
184
  return str(e), str(e), capture.get_output()
185
 
186
  finally:
187
+ # Always return to the original working directory after processing
188
+ os.chdir(original_dir)
189
  sys.stdout = sys.__stdout__ # Reset print statements
190
 
191
  # Function to handle logic based on whether a file is uploaded or not