Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
|
@@ -64,6 +64,8 @@ cmap_select_2d = pn.widgets.Select(name='2D Colormap', options=["rainbow", "viri
|
|
| 64 |
|
| 65 |
# ---------------- Core Functions ----------------
|
| 66 |
def process_zip(event=None):
|
|
|
|
|
|
|
| 67 |
if file_input.value:
|
| 68 |
zip_path = os.path.join(MEDIA_DIR, file_input.filename)
|
| 69 |
with open(zip_path, "wb") as f:
|
|
@@ -76,17 +78,15 @@ def process_zip(event=None):
|
|
| 76 |
return
|
| 77 |
status.object = "📦 Using default_model.zip"
|
| 78 |
|
| 79 |
-
|
|
|
|
| 80 |
shutil.rmtree(output_dir, ignore_errors=True)
|
| 81 |
os.makedirs(output_dir, exist_ok=True)
|
| 82 |
|
| 83 |
try:
|
| 84 |
processor = NAMEDataProcessor(output_root=output_dir)
|
| 85 |
-
processor.batch_process_zip(zip_path)
|
| 86 |
|
| 87 |
-
# animator_obj["3d"] = [xr.open_dataset(fp).load()
|
| 88 |
-
# for fp in sorted(glob.glob(os.path.join(output_dir, "3D", "*.nc")))]
|
| 89 |
-
|
| 90 |
animator_obj["3d"] = []
|
| 91 |
for fp in sorted(glob.glob(os.path.join(output_dir, "3D", "*.nc"))):
|
| 92 |
with xr.open_dataset(fp) as ds:
|
|
@@ -97,15 +97,12 @@ def process_zip(event=None):
|
|
| 97 |
with xr.open_dataset(fp) as ds:
|
| 98 |
animator_obj["2d"].append(ds.load())
|
| 99 |
|
| 100 |
-
|
| 101 |
-
# animator_obj["2d"] = [xr.open_dataset(fp).load()
|
| 102 |
-
# for fp in sorted(glob.glob(os.path.join(output_dir, "horizontal", "*.nc")))]
|
| 103 |
-
|
| 104 |
with open(os.path.join(MEDIA_DIR, "last_run.txt"), "w") as f:
|
| 105 |
f.write(zip_path)
|
| 106 |
|
| 107 |
status.object += f" | ✅ Loaded 3D: {len(animator_obj['3d'])} & 2D: {len(animator_obj['2d'])}"
|
| 108 |
update_media_tabs()
|
|
|
|
| 109 |
except Exception as e:
|
| 110 |
logging.exception("Error during ZIP processing")
|
| 111 |
status.object = f"❌ Processing failed: {e}"
|
|
|
|
| 64 |
|
| 65 |
# ---------------- Core Functions ----------------
|
| 66 |
def process_zip(event=None):
|
| 67 |
+
import tempfile
|
| 68 |
+
|
| 69 |
if file_input.value:
|
| 70 |
zip_path = os.path.join(MEDIA_DIR, file_input.filename)
|
| 71 |
with open(zip_path, "wb") as f:
|
|
|
|
| 78 |
return
|
| 79 |
status.object = "📦 Using default_model.zip"
|
| 80 |
|
| 81 |
+
# Use safe temporary output directory
|
| 82 |
+
output_dir = os.path.join(tempfile.gettempdir(), "ash_output")
|
| 83 |
shutil.rmtree(output_dir, ignore_errors=True)
|
| 84 |
os.makedirs(output_dir, exist_ok=True)
|
| 85 |
|
| 86 |
try:
|
| 87 |
processor = NAMEDataProcessor(output_root=output_dir)
|
| 88 |
+
processor.batch_process_zip(zip_path) # This must also use a writable temp dir internally
|
| 89 |
|
|
|
|
|
|
|
|
|
|
| 90 |
animator_obj["3d"] = []
|
| 91 |
for fp in sorted(glob.glob(os.path.join(output_dir, "3D", "*.nc"))):
|
| 92 |
with xr.open_dataset(fp) as ds:
|
|
|
|
| 97 |
with xr.open_dataset(fp) as ds:
|
| 98 |
animator_obj["2d"].append(ds.load())
|
| 99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
with open(os.path.join(MEDIA_DIR, "last_run.txt"), "w") as f:
|
| 101 |
f.write(zip_path)
|
| 102 |
|
| 103 |
status.object += f" | ✅ Loaded 3D: {len(animator_obj['3d'])} & 2D: {len(animator_obj['2d'])}"
|
| 104 |
update_media_tabs()
|
| 105 |
+
|
| 106 |
except Exception as e:
|
| 107 |
logging.exception("Error during ZIP processing")
|
| 108 |
status.object = f"❌ Processing failed: {e}"
|