Spaces:
Running
Running
Sadjad Alikhani
commited on
Update app.py
Browse files
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 |
-
#
|
116 |
-
|
|
|
|
|
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 |
-
|
131 |
-
|
|
|
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 {
|
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
|