Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -273,9 +273,10 @@ def handle_file_upload(uploaded_file, last_file_info):
|
|
| 273 |
return "No file uploaded.", gr.update(interactive=False), gr.update(visible=False), [None, None], {}
|
| 274 |
|
| 275 |
file_path = uploaded_file.name
|
| 276 |
-
|
| 277 |
-
if
|
| 278 |
-
|
|
|
|
| 279 |
|
| 280 |
current_file_size = os.path.getsize(file_path)
|
| 281 |
current_mod_time = os.path.getmtime(file_path)
|
|
@@ -299,12 +300,23 @@ def handle_file_upload(uploaded_file, last_file_info):
|
|
| 299 |
|
| 300 |
# If new file or a different version, proceed with conversion
|
| 301 |
temp_root = os.path.join(tempfile.gettempdir(), f"temp_pts_{uuid.uuid4().hex}")
|
| 302 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 303 |
|
| 304 |
pts_npy_path = os.path.join(temp_root, "cloud_points.npy")
|
| 305 |
cols_npy_path = os.path.join(temp_root, "cloud_colors.npy")
|
| 306 |
|
| 307 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 308 |
|
| 309 |
# Store info for future re-uploads in the state dictionary
|
| 310 |
new_file_info = {
|
|
@@ -326,6 +338,10 @@ def start_analysis(file_state, progress=gr.Progress(track_tqdm=True)):
|
|
| 326 |
Performs the full analysis on the pre-loaded .npy files.
|
| 327 |
Uses 'yield' to provide progressive updates to the UI.
|
| 328 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 329 |
pts_npy_path, cols_npy_path = file_state
|
| 330 |
|
| 331 |
if not (pts_npy_path and cols_npy_path and os.path.exists(pts_npy_path)):
|
|
|
|
| 273 |
return "No file uploaded.", gr.update(interactive=False), gr.update(visible=False), [None, None], {}
|
| 274 |
|
| 275 |
file_path = uploaded_file.name
|
| 276 |
+
|
| 277 |
+
# Check if the file path is valid before proceeding
|
| 278 |
+
if not file_path or not os.path.exists(file_path):
|
| 279 |
+
return "Error: Uploaded file not found or invalid.", gr.update(interactive=False), gr.update(visible=False), [None, None], {}
|
| 280 |
|
| 281 |
current_file_size = os.path.getsize(file_path)
|
| 282 |
current_mod_time = os.path.getmtime(file_path)
|
|
|
|
| 300 |
|
| 301 |
# If new file or a different version, proceed with conversion
|
| 302 |
temp_root = os.path.join(tempfile.gettempdir(), f"temp_pts_{uuid.uuid4().hex}")
|
| 303 |
+
|
| 304 |
+
try:
|
| 305 |
+
os.makedirs(temp_root, exist_ok=True)
|
| 306 |
+
except OSError as e:
|
| 307 |
+
error_message = f"Error: Failed to create a temporary directory at '{temp_root}'. Details: {e}"
|
| 308 |
+
print(error_message)
|
| 309 |
+
return error_message, gr.update(interactive=False), gr.update(visible=False), [None, None], {}
|
| 310 |
|
| 311 |
pts_npy_path = os.path.join(temp_root, "cloud_points.npy")
|
| 312 |
cols_npy_path = os.path.join(temp_root, "cloud_colors.npy")
|
| 313 |
|
| 314 |
+
try:
|
| 315 |
+
pts_to_npy(file_path, pts_npy_path, cols_npy_path)
|
| 316 |
+
except Exception as e:
|
| 317 |
+
error_message = f"Error: Failed to convert .pts file. Please check file format. Details: {e}"
|
| 318 |
+
print(error_message)
|
| 319 |
+
return error_message, gr.update(interactive=False), gr.update(visible=False), [None, None], {}
|
| 320 |
|
| 321 |
# Store info for future re-uploads in the state dictionary
|
| 322 |
new_file_info = {
|
|
|
|
| 338 |
Performs the full analysis on the pre-loaded .npy files.
|
| 339 |
Uses 'yield' to provide progressive updates to the UI.
|
| 340 |
"""
|
| 341 |
+
# Defensive check to prevent the TypeError
|
| 342 |
+
if not file_state or not file_state[0]:
|
| 343 |
+
return "Please upload a file and wait for it to load before starting the analysis.", None, None, gr.update(interactive=False)
|
| 344 |
+
|
| 345 |
pts_npy_path, cols_npy_path = file_state
|
| 346 |
|
| 347 |
if not (pts_npy_path and cols_npy_path and os.path.exists(pts_npy_path)):
|