m8flow 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -67,6 +67,21 @@ def _serialize_value(value: Any) -> Any:
67
67
  return bool(value)
68
68
 
69
69
  # ── sklearn ──────────────────────────────────────────────────────────────
70
+ is_display = hasattr(value, "figure_") and hasattr(value.figure_, "savefig")
71
+ if is_display:
72
+ try:
73
+ import io
74
+ import base64
75
+ buf = io.BytesIO()
76
+ value.figure_.savefig(buf, format="png", bbox_inches="tight")
77
+ b64 = base64.b64encode(buf.getvalue()).decode("utf-8")
78
+ return {
79
+ "image_base64": b64,
80
+ "title": getattr(value, "estimator_name", type(value).__name__)
81
+ }
82
+ except Exception:
83
+ pass
84
+
70
85
  if isinstance(value, BaseEstimator):
71
86
  params = {}
72
87
  for k, v in value.get_params().items():
@@ -76,6 +91,32 @@ def _serialize_value(value: Any) -> Any:
76
91
  params[k] = str(v)
77
92
  return {"_type": "Estimator", "class": type(value).__name__, "params": params}
78
93
 
94
+ # ── matplotlib / seaborn ──────────────────────────────────────────────────
95
+ is_figure = hasattr(value, "savefig") and type(value).__module__.startswith("matplotlib")
96
+ if is_figure:
97
+ try:
98
+ import io
99
+ import base64
100
+ buf = io.BytesIO()
101
+ value.savefig(buf, format="png", bbox_inches="tight")
102
+ b64 = base64.b64encode(buf.getvalue()).decode("utf-8")
103
+ return {
104
+ "image_base64": b64,
105
+ "title": "Matplotlib / Seaborn Plot"
106
+ }
107
+ except Exception:
108
+ pass
109
+
110
+ # ── plotly ───────────────────────────────────────────────────────────────
111
+ if hasattr(value, "to_html") and type(value).__module__.startswith("plotly"):
112
+ try:
113
+ return {
114
+ "plotly_html": value.to_html(full_html=False, include_plotlyjs="cdn"),
115
+ "title": "Plotly Visualization"
116
+ }
117
+ except Exception:
118
+ pass
119
+
79
120
  # ── plain Python scalars ─────────────────────────────────────────────────
80
121
  if isinstance(value, float):
81
122
  return _safe_float(value)
@@ -3,20 +3,15 @@
3
3
  # ── Data ──────────────────────────────────────────────────────────────────────
4
4
 
5
5
  CSV_LOADER = '''import pandas as pd
6
- import os
7
- from typing import Annotated
8
6
 
9
- def run(file_path: Annotated[str, "file"] = "data.csv") -> dict:
10
- """Loads a CSV file. Looks in the storage directory if a relative path is provided."""
11
- # Resolve path
12
- if not os.path.isabs(file_path):
13
- storage_dir = os.environ.get("M8FLOW_UPLOAD_DIR") or os.path.abspath("uploads")
14
- potential_path = os.path.join(storage_dir, file_path)
15
- if os.path.exists(potential_path):
16
- file_path = potential_path
17
-
18
- df = pd.read_csv(file_path)
19
- return {"data": df}
7
+ def run(file_path=None):
8
+ if file_path is None:
9
+ raise ValueError("No file path provided")
10
+ try:
11
+ data = pd.read_csv(file_path)
12
+ return {"data": data}
13
+ except Exception as e:
14
+ raise ValueError(f"Failed to load CSV: {str(e)}")
20
15
  '''
21
16
 
22
17
  CSV_EXPORTER = '''import pandas as pd