mnoorchenar commited on
Commit
84e5a7a
Β·
1 Parent(s): b37f2fb

Update 2026-03-25 15:35:35

Browse files
Files changed (2) hide show
  1. app.py +4 -4
  2. mlops/algorithms.py +16 -0
app.py CHANGED
@@ -9,7 +9,7 @@ import mlflow.sklearn
9
  from flask import Flask, render_template, request, jsonify
10
 
11
  from mlops.datasets import DATASETS, load_dataset
12
- from mlops.algorithms import ALGORITHMS, list_algorithms, all_algorithm_names
13
  from mlops.trainer import (
14
  training_jobs, automl_jobs,
15
  start_training, start_automl,
@@ -144,7 +144,7 @@ def dashboard():
144
  algo_counts=json.dumps(algo_counts),
145
  ds_counts=json.dumps(ds_counts),
146
  datasets=DATASETS,
147
- algorithms=ALGORITHMS)
148
 
149
 
150
  @app.route("/experiments")
@@ -255,7 +255,7 @@ def models():
255
  def automl():
256
  return render_template("automl.html",
257
  datasets=DATASETS,
258
- algorithms=ALGORITHMS)
259
 
260
 
261
  # ══════════════════════════════════════════════════════════════════════════════
@@ -426,7 +426,7 @@ def api_automl_status(job_id):
426
  def api_algorithms():
427
  task = request.args.get("task", "classification")
428
  try:
429
- return jsonify(list_algorithms(task))
430
  except ValueError as e:
431
  return jsonify({"error": str(e)}), 400
432
 
 
9
  from flask import Flask, render_template, request, jsonify
10
 
11
  from mlops.datasets import DATASETS, load_dataset
12
+ from mlops.algorithms import ALGORITHMS, list_algorithms, all_algorithm_names, algorithms_for_json
13
  from mlops.trainer import (
14
  training_jobs, automl_jobs,
15
  start_training, start_automl,
 
144
  algo_counts=json.dumps(algo_counts),
145
  ds_counts=json.dumps(ds_counts),
146
  datasets=DATASETS,
147
+ algorithms=algorithms_for_json())
148
 
149
 
150
  @app.route("/experiments")
 
255
  def automl():
256
  return render_template("automl.html",
257
  datasets=DATASETS,
258
+ algorithms=algorithms_for_json())
259
 
260
 
261
  # ══════════════════════════════════════════════════════════════════════════════
 
426
  def api_algorithms():
427
  task = request.args.get("task", "classification")
428
  try:
429
+ return jsonify(algorithms_for_json(task))
430
  except ValueError as e:
431
  return jsonify({"error": str(e)}), 400
432
 
mlops/algorithms.py CHANGED
@@ -390,3 +390,19 @@ def all_algorithm_names(task: str) -> list[str]:
390
  for cat in ALGORITHMS[task].values():
391
  names.extend(cat.keys())
392
  return names
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
390
  for cat in ALGORITHMS[task].values():
391
  names.extend(cat.keys())
392
  return names
393
+
394
+
395
+ def algorithms_for_json(task: str | None = None) -> dict:
396
+ """Return ALGORITHMS (or a task subset) as a JSON-serializable dict.
397
+
398
+ Removes the non-serializable ``"class"`` key and converts tuples to lists.
399
+ """
400
+ def _clean(obj):
401
+ if isinstance(obj, dict):
402
+ return {k: _clean(v) for k, v in obj.items() if k != "class"}
403
+ if isinstance(obj, (list, tuple)):
404
+ return [_clean(i) for i in obj]
405
+ return obj
406
+
407
+ src = ALGORITHMS if task is None else ALGORITHMS[task]
408
+ return _clean(src)