Update visualizer_app.py
Browse files- visualizer_app.py +47 -40
visualizer_app.py
CHANGED
|
@@ -3,7 +3,6 @@
|
|
| 3 |
# custom_css = ["./custom_header_font.css"]
|
| 4 |
# ///
|
| 5 |
|
| 6 |
-
|
| 7 |
import marimo
|
| 8 |
|
| 9 |
__generated_with = "0.13.0"
|
|
@@ -89,7 +88,6 @@ def client_variables(client_instantiation_form):
|
|
| 89 |
else:
|
| 90 |
os.environ["WATSONX_APIKEY"] = ""
|
| 91 |
project_id = space_id = wx_api_key = wx_url = None
|
| 92 |
-
|
| 93 |
return client_setup, project_id, space_id, wx_api_key, wx_url
|
| 94 |
|
| 95 |
|
|
@@ -115,21 +113,13 @@ def _():
|
|
| 115 |
markdown_spacing,
|
| 116 |
)
|
| 117 |
|
| 118 |
-
|
| 119 |
@app.cell
|
| 120 |
def client_instantiation(
|
| 121 |
APIClient,
|
| 122 |
Credentials,
|
| 123 |
-
client,
|
| 124 |
-
client_key,
|
| 125 |
-
client_options,
|
| 126 |
-
client_selector,
|
| 127 |
client_setup,
|
| 128 |
-
get_key_by_value,
|
| 129 |
-
mo,
|
| 130 |
project_id,
|
| 131 |
space_id,
|
| 132 |
-
wrap_with_spaces,
|
| 133 |
wx_api_key,
|
| 134 |
wx_url,
|
| 135 |
):
|
|
@@ -137,48 +127,31 @@ def client_instantiation(
|
|
| 137 |
if client_setup:
|
| 138 |
try:
|
| 139 |
wx_credentials = Credentials(url=wx_url, api_key=wx_api_key)
|
| 140 |
-
|
| 141 |
project_client = (
|
| 142 |
APIClient(credentials=wx_credentials, project_id=project_id)
|
| 143 |
if project_id
|
| 144 |
else None
|
| 145 |
)
|
| 146 |
-
|
| 147 |
deployment_client = (
|
| 148 |
APIClient(credentials=wx_credentials, space_id=space_id)
|
| 149 |
if space_id
|
| 150 |
else None
|
| 151 |
)
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
client_status = mo.md(
|
| 155 |
-
f"### ✅ Client Instantiation Successful ✅\n\n"
|
| 156 |
-
f"{client_selector}\n\n"
|
| 157 |
-
f"**Active Client:**{wrap_with_spaces(active_client_name, prefix_spaces=5)}"
|
| 158 |
-
)
|
| 159 |
-
client_callout_kind = "success"
|
| 160 |
-
|
| 161 |
except Exception as e:
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
f"### ❌ Client Instantiation Failed\n**Error:** {error_message}\n\nCheck your region selection and credentials"
|
| 165 |
-
)
|
| 166 |
-
client_callout_kind = "danger"
|
| 167 |
wx_credentials = project_client = deployment_client = None
|
| 168 |
else:
|
| 169 |
wx_credentials = project_client = deployment_client = None
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
f"{client_selector}\n\n"
|
| 174 |
-
f"**Active Client:**{wrap_with_spaces(active_client_name, prefix_spaces=5)}"
|
| 175 |
-
)
|
| 176 |
-
client_callout_kind = "neutral"
|
| 177 |
-
|
| 178 |
return (
|
| 179 |
-
client_callout_kind,
|
| 180 |
-
client_status,
|
| 181 |
deployment_client,
|
|
|
|
|
|
|
| 182 |
project_client,
|
| 183 |
)
|
| 184 |
|
|
@@ -429,6 +402,42 @@ def instantiation_status(
|
|
| 429 |
client_stack = mo.hstack([client_instantiation_form, client_callout], align="center", justify="space-around", gap=10)
|
| 430 |
return (client_stack,)
|
| 431 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 432 |
|
| 433 |
@app.cell
|
| 434 |
def client_selector(deployment_client, project_client):
|
|
@@ -446,8 +455,7 @@ def client_selector(deployment_client, project_client):
|
|
| 446 |
|
| 447 |
default_client = next(iter(client_options))
|
| 448 |
client_selector = mo.ui.dropdown(client_options, value=default_client, label="**Select your active client:**")
|
| 449 |
-
|
| 450 |
-
return (client_selector,)
|
| 451 |
|
| 452 |
|
| 453 |
@app.cell
|
|
@@ -457,8 +465,7 @@ def active_client(client_selector):
|
|
| 457 |
client = None
|
| 458 |
else:
|
| 459 |
client = client_key
|
| 460 |
-
return
|
| 461 |
-
|
| 462 |
|
| 463 |
@app.cell
|
| 464 |
def emb_model_selection(client, set_embedding_model_list):
|
|
|
|
| 3 |
# custom_css = ["./custom_header_font.css"]
|
| 4 |
# ///
|
| 5 |
|
|
|
|
| 6 |
import marimo
|
| 7 |
|
| 8 |
__generated_with = "0.13.0"
|
|
|
|
| 88 |
else:
|
| 89 |
os.environ["WATSONX_APIKEY"] = ""
|
| 90 |
project_id = space_id = wx_api_key = wx_url = None
|
|
|
|
| 91 |
return client_setup, project_id, space_id, wx_api_key, wx_url
|
| 92 |
|
| 93 |
|
|
|
|
| 113 |
markdown_spacing,
|
| 114 |
)
|
| 115 |
|
|
|
|
| 116 |
@app.cell
|
| 117 |
def client_instantiation(
|
| 118 |
APIClient,
|
| 119 |
Credentials,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
client_setup,
|
|
|
|
|
|
|
| 121 |
project_id,
|
| 122 |
space_id,
|
|
|
|
| 123 |
wx_api_key,
|
| 124 |
wx_url,
|
| 125 |
):
|
|
|
|
| 127 |
if client_setup:
|
| 128 |
try:
|
| 129 |
wx_credentials = Credentials(url=wx_url, api_key=wx_api_key)
|
|
|
|
| 130 |
project_client = (
|
| 131 |
APIClient(credentials=wx_credentials, project_id=project_id)
|
| 132 |
if project_id
|
| 133 |
else None
|
| 134 |
)
|
|
|
|
| 135 |
deployment_client = (
|
| 136 |
APIClient(credentials=wx_credentials, space_id=space_id)
|
| 137 |
if space_id
|
| 138 |
else None
|
| 139 |
)
|
| 140 |
+
instantiation_success = True
|
| 141 |
+
instantiation_error = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
except Exception as e:
|
| 143 |
+
instantiation_success = False
|
| 144 |
+
instantiation_error = str(e)
|
|
|
|
|
|
|
|
|
|
| 145 |
wx_credentials = project_client = deployment_client = None
|
| 146 |
else:
|
| 147 |
wx_credentials = project_client = deployment_client = None
|
| 148 |
+
instantiation_success = None
|
| 149 |
+
instantiation_error = None
|
| 150 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
return (
|
|
|
|
|
|
|
| 152 |
deployment_client,
|
| 153 |
+
instantiation_error,
|
| 154 |
+
instantiation_success,
|
| 155 |
project_client,
|
| 156 |
)
|
| 157 |
|
|
|
|
| 402 |
client_stack = mo.hstack([client_instantiation_form, client_callout], align="center", justify="space-around", gap=10)
|
| 403 |
return (client_stack,)
|
| 404 |
|
| 405 |
+
def _(
|
| 406 |
+
client,
|
| 407 |
+
client_key,
|
| 408 |
+
client_options,
|
| 409 |
+
client_selector,
|
| 410 |
+
client_setup,
|
| 411 |
+
get_key_by_value,
|
| 412 |
+
instantiation_error,
|
| 413 |
+
instantiation_success,
|
| 414 |
+
mo,
|
| 415 |
+
wrap_with_spaces,
|
| 416 |
+
):
|
| 417 |
+
active_client_name = get_key_by_value(client_options, client_key)
|
| 418 |
+
|
| 419 |
+
if client_setup:
|
| 420 |
+
if instantiation_success:
|
| 421 |
+
client_status = mo.md(
|
| 422 |
+
f"### ✅ Client Instantiation Successful ✅\n\n"
|
| 423 |
+
f"{client_selector}\n\n"
|
| 424 |
+
f"**Active Client:**{wrap_with_spaces(active_client_name, prefix_spaces=5)}"
|
| 425 |
+
)
|
| 426 |
+
client_callout_kind = "success"
|
| 427 |
+
else:
|
| 428 |
+
client_status = mo.md(
|
| 429 |
+
f"### ❌ Client Instantiation Failed\n**Error:** {instantiation_error}\n\nCheck your region selection and credentials"
|
| 430 |
+
)
|
| 431 |
+
client_callout_kind = "danger"
|
| 432 |
+
else:
|
| 433 |
+
client_status = mo.md(
|
| 434 |
+
f"### Client Instantiation Status will turn Green When Ready\n\n"
|
| 435 |
+
f"{client_selector}\n\n"
|
| 436 |
+
f"**Active Client:**{wrap_with_spaces(active_client_name, prefix_spaces=5)}"
|
| 437 |
+
)
|
| 438 |
+
client_callout_kind = "neutral"
|
| 439 |
+
|
| 440 |
+
return active_client_name, client_callout_kind, client_status
|
| 441 |
|
| 442 |
@app.cell
|
| 443 |
def client_selector(deployment_client, project_client):
|
|
|
|
| 455 |
|
| 456 |
default_client = next(iter(client_options))
|
| 457 |
client_selector = mo.ui.dropdown(client_options, value=default_client, label="**Select your active client:**")
|
| 458 |
+
return client_options, client_selector
|
|
|
|
| 459 |
|
| 460 |
|
| 461 |
@app.cell
|
|
|
|
| 465 |
client = None
|
| 466 |
else:
|
| 467 |
client = client_key
|
| 468 |
+
return client, client_key
|
|
|
|
| 469 |
|
| 470 |
@app.cell
|
| 471 |
def emb_model_selection(client, set_embedding_model_list):
|