UI 访问与 Notebook 集成
远程 SDK 访问
MLflow Python SDK 无需特殊配置即可连接到远程跟踪服务器。
import mlflow
# Connect to remote server
mlflow.set_tracking_uri("http://mlflow.company.com:5000")
with mlflow.start_run():
mlflow.log_param("alpha", 0.5)
mlflow.log_metric("rmse", 0.1)
Jupyter Notebook 集成
Jupyter Notebook 可以使用 iframe 嵌入 MLflow UI 组件。
跨域 Notebook
当 Notebook 运行在与您的 MLflow 服务器不同的域上时,请配置 CORS 和 frame 选项。
# Allow embedding from notebook domain
mlflow server --host 0.0.0.0 \
--x-frame-options NONE \
--cors-allowed-origins "https://jupyter.company.com"
手动 iframe 嵌入
直接在 Notebook 单元格中嵌入特定的 MLflow 视图。
from IPython.display import IFrame
# Embed MLflow UI
IFrame(src="http://mlflow.company.com:5000", width=1000, height=600)
嵌入 Web 应用程序
Web 应用程序可以使用 iframe 嵌入 MLflow UI。
React 应用程序
创建一个组件来显示 MLflow 内容。
function MLflowDashboard() {
return (
<iframe
src="http://mlflow.company.com:5000/experiments/1"
style={{ width: '100%', height: '800px' }}
title="MLflow"
/>
);
}
配置 MLflow 服务器以接受来自您的 React 应用的请求。
mlflow server --host 0.0.0.0 \
--x-frame-options NONE \
--cors-allowed-origins "https://:3000,https://app.company.com"
测试 iframe 嵌入
使用此 HTML 文件来验证 iframe 配置是否正常工作。
<!DOCTYPE html>
<html>
<head>
<title>MLflow iframe Test</title>
</head>
<body>
<h1>MLflow Embedding Test</h1>
<iframe
src="https://:5000"
style="width: 100%; height: 600px; border: 1px solid #ccc;"
onload="document.getElementById('status').innerHTML = '✅ Loaded'"
onerror="document.getElementById('status').innerHTML = '❌ Failed'">
</iframe>
<div id="status">Loading...</div>
</body>
</html>