Mahmudm commited on
Commit
c3e3209
·
verified ·
1 Parent(s): edcc1dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -6
app.py CHANGED
@@ -64,8 +64,6 @@ cmap_select_2d = pn.widgets.Select(name='2D Colormap', options=["rainbow", "viri
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:
@@ -73,20 +71,34 @@ def process_zip(event=None):
73
  status.object = "✅ ZIP uploaded and saved."
74
  else:
75
  zip_path = os.path.join(MEDIA_DIR, "default_model.zip")
 
 
76
  if not os.path.exists(zip_path):
77
  status.object = "❌ No ZIP uploaded and default_model.zip not found."
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,12 +109,15 @@ def process_zip(event=None):
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}"
 
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:
 
71
  status.object = "✅ ZIP uploaded and saved."
72
  else:
73
  zip_path = os.path.join(MEDIA_DIR, "default_model.zip")
74
+ if not os.path.exists(zip_path):
75
+ zip_path = "default_model.zip" # fallback to local directory
76
  if not os.path.exists(zip_path):
77
  status.object = "❌ No ZIP uploaded and default_model.zip not found."
78
  return
79
  status.object = "📦 Using default_model.zip"
80
 
81
+
82
+ try:
83
+ output_dir = os.path.join("./", "ash_output")
84
+ os.makedirs(output_dir, exist_ok=True)
85
+ except PermissionError:
86
+ output_dir = os.path.join(tempfile.gettempdir(), "name_output")
87
+ os.makedirs(output_dir, exist_ok=True)
88
  shutil.rmtree(output_dir, ignore_errors=True)
89
  os.makedirs(output_dir, exist_ok=True)
90
 
91
  try:
92
  processor = NAMEDataProcessor(output_root=output_dir)
93
+ processor.batch_process_zip(zip_path)
94
 
95
+ # animator_obj["3d"] = [xr.open_dataset(fp).load()
96
+ # for fp in sorted(glob.glob(os.path.join(output_dir, "3D", "*.nc")))]
97
+
98
+ # animator_obj["3d"] = []
99
+ # for fp in sorted(glob.glob(os.path.join(output_dir, "3D", "*.nc"))):
100
+ # with xr.open_dataset(fp) as ds:
101
+ # animator_obj["3d"].append(ds.load())
102
  animator_obj["3d"] = []
103
  for fp in sorted(glob.glob(os.path.join(output_dir, "3D", "*.nc"))):
104
  with xr.open_dataset(fp) as ds:
 
109
  with xr.open_dataset(fp) as ds:
110
  animator_obj["2d"].append(ds.load())
111
 
112
+
113
+ # animator_obj["2d"] = [xr.open_dataset(fp).load()
114
+ # for fp in sorted(glob.glob(os.path.join(output_dir, "horizontal", "*.nc")))]
115
+
116
  with open(os.path.join(MEDIA_DIR, "last_run.txt"), "w") as f:
117
  f.write(zip_path)
118
 
119
  status.object += f" | ✅ Loaded 3D: {len(animator_obj['3d'])} & 2D: {len(animator_obj['2d'])}"
120
  update_media_tabs()
 
121
  except Exception as e:
122
  logging.exception("Error during ZIP processing")
123
  status.object = f"❌ Processing failed: {e}"