harrytarlton commited on
Commit
a690306
Β·
1 Parent(s): aaa248c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -7
app.py CHANGED
@@ -111,31 +111,41 @@ class NAMProcessor:
111
  self.current_model_name = None
112
  self.processed_files = []
113
  self.custom_models = {} # Store user's cloud models
 
114
  self.load_available_models()
115
 
116
  def load_available_models(self):
117
- """Load all available NAM models"""
 
118
  if not MODELS_DIR.exists():
119
  print(f"Creating models directory: {MODELS_DIR}")
120
  MODELS_DIR.mkdir(exist_ok=True)
121
 
122
  nam_files = list(MODELS_DIR.glob("*.nam"))
123
  print(f"Found {len(nam_files)} local NAM model files")
 
 
 
 
124
 
125
  for nam_file in nam_files:
126
  try:
 
127
  with open(nam_file, 'r', encoding='utf-8') as f:
128
  data = json.load(f)
129
  model_name = nam_file.stem
 
130
  self.models[model_name] = {
131
  'path': nam_file,
132
- 'data': data,
133
  'metadata': data.get('metadata', {}),
134
  'source': 'local'
135
  }
136
- print(f"Loaded local model: {model_name}")
137
  except Exception as e:
138
- print(f"Error loading {nam_file}: {e}")
 
 
139
 
140
  def download_from_url(self, url: str, model_name: str = None) -> bool:
141
  """Download NAM model from URL (supports direct links, Google Drive, Dropbox)"""
@@ -234,8 +244,6 @@ class NAMProcessor:
234
  if not self.models:
235
  # Try loading again in case models weren't loaded
236
  self.load_available_models()
237
- if not self.models:
238
- return ["No models found - Add cloud models below"]
239
 
240
  choices = []
241
 
@@ -254,7 +262,16 @@ class NAMProcessor:
254
  choices.append("━━━ ☁️ Cloud Models ━━━")
255
  choices.extend(sorted(cloud_models))
256
 
257
- return choices if choices else ["No models found"]
 
 
 
 
 
 
 
 
 
258
 
259
  def clear_custom_models(self):
260
  """Clear all custom cloud models"""
 
111
  self.current_model_name = None
112
  self.processed_files = []
113
  self.custom_models = {} # Store user's cloud models
114
+ self.loading_errors = []
115
  self.load_available_models()
116
 
117
  def load_available_models(self):
118
+ """Load metadata for available NAM models (lazy loading)"""
119
+ self.loading_errors = []
120
  if not MODELS_DIR.exists():
121
  print(f"Creating models directory: {MODELS_DIR}")
122
  MODELS_DIR.mkdir(exist_ok=True)
123
 
124
  nam_files = list(MODELS_DIR.glob("*.nam"))
125
  print(f"Found {len(nam_files)} local NAM model files")
126
+
127
+ if not nam_files:
128
+ self.loading_errors.append("No .nam files found in 'models' directory.")
129
+ return
130
 
131
  for nam_file in nam_files:
132
  try:
133
+ # Only load metadata, not the full model data
134
  with open(nam_file, 'r', encoding='utf-8') as f:
135
  data = json.load(f)
136
  model_name = nam_file.stem
137
+ # Store path and metadata only, load data on demand
138
  self.models[model_name] = {
139
  'path': nam_file,
140
+ 'data': None, # Will load on demand
141
  'metadata': data.get('metadata', {}),
142
  'source': 'local'
143
  }
144
+ print(f"Indexed local model: {model_name}")
145
  except Exception as e:
146
+ error_msg = f"Error indexing {nam_file.name}: {e}"
147
+ print(error_msg)
148
+ self.loading_errors.append(error_msg)
149
 
150
  def download_from_url(self, url: str, model_name: str = None) -> bool:
151
  """Download NAM model from URL (supports direct links, Google Drive, Dropbox)"""
 
244
  if not self.models:
245
  # Try loading again in case models weren't loaded
246
  self.load_available_models()
 
 
247
 
248
  choices = []
249
 
 
262
  choices.append("━━━ ☁️ Cloud Models ━━━")
263
  choices.extend(sorted(cloud_models))
264
 
265
+ if self.loading_errors:
266
+ choices.append("━━━ ⚠️ Loading Errors ━━━")
267
+ for err in self.loading_errors:
268
+ # Truncate long error messages for display
269
+ choices.append(err[:100] + '...' if len(err) > 100 else err)
270
+
271
+ if not choices:
272
+ return ["No models found - Add cloud models below"]
273
+
274
+ return choices
275
 
276
  def clear_custom_models(self):
277
  """Clear all custom cloud models"""