DraconicDragon commited on
Commit
8b7a2c5
·
verified ·
1 Parent(s): 54ff052

attempt to dynamically add cl tagger versions as they release

Browse files
Files changed (1) hide show
  1. app.py +26 -6
app.py CHANGED
@@ -270,15 +270,35 @@ def visualize_predictions(image: Image.Image, predictions: Dict, threshold: floa
270
  buf.seek(0)
271
  return Image.open(buf)
272
 
273
- # --- Constants ---
274
  REPO_ID = "cella110n/cl_tagger"
275
- MODEL_OPTIONS = {
276
- "cl_tagger_1_00": "cl_tagger_1_00/model_optimized.onnx",
277
- "cl_tagger_1_01": "cl_tagger_1_01/model_optimized.onnx"
278
- }
279
- DEFAULT_MODEL = "cl_tagger_1_01"
280
  CACHE_DIR = "./model_cache"
281
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
282
  # --- Global variables for paths (initialized at startup) ---
283
  g_onnx_model_path = None
284
  g_tag_mapping_path = None
 
270
  buf.seek(0)
271
  return Image.open(buf)
272
 
273
+ # --- Dynamic Model Discovery ---
274
  REPO_ID = "cella110n/cl_tagger"
 
 
 
 
 
275
  CACHE_DIR = "./model_cache"
276
 
277
+ def discover_models(repo_id=REPO_ID):
278
+ api = HfApi()
279
+ files = api.list_repo_files(repo_id=repo_id)
280
+
281
+ model_options = {}
282
+ for f in files:
283
+ # look for ONNX models in subfolders
284
+ if f.endswith("model_optimized.onnx"):
285
+ # take the parent folder as model key
286
+ parts = f.split("/")
287
+ if len(parts) >= 2:
288
+ model_key = parts[0] # e.g., "cl_tagger_1_01"
289
+ model_options[model_key] = f
290
+
291
+ if not model_options:
292
+ raise RuntimeError(f"No ONNX models found in {repo_id}")
293
+
294
+ # pick the latest model as default (sorted by name)
295
+ default_model = sorted(model_options.keys())[-1]
296
+
297
+ return model_options, default_model
298
+
299
+ # Build dynamically
300
+ MODEL_OPTIONS, DEFAULT_MODEL = discover_models()
301
+
302
  # --- Global variables for paths (initialized at startup) ---
303
  g_onnx_model_path = None
304
  g_tag_mapping_path = None