Update app.py
Browse files
app.py
CHANGED
@@ -201,46 +201,70 @@ def _(client_instantiation_form, os):
|
|
201 |
|
202 |
|
203 |
@app.cell
|
204 |
-
def
|
205 |
APIClient,
|
206 |
Credentials,
|
|
|
|
|
|
|
|
|
207 |
client_setup,
|
|
|
|
|
208 |
project_id,
|
209 |
space_id,
|
|
|
210 |
wx_api_key,
|
211 |
wx_url,
|
212 |
):
|
|
|
213 |
if client_setup:
|
214 |
-
|
215 |
-
|
216 |
|
217 |
-
|
218 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
219 |
|
220 |
-
|
221 |
-
|
|
|
|
|
|
|
|
|
|
|
222 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
223 |
else:
|
224 |
wx_credentials = project_client = deployment_client = None
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
client_options,
|
233 |
-
client_selector,
|
234 |
-
get_key_by_value,
|
235 |
-
mo,
|
236 |
-
wrap_with_spaces,
|
237 |
-
):
|
238 |
-
active_client_name = get_key_by_value(client_options,client_key)
|
239 |
-
client_status = mo.md(f"### Client Instantiation Status will turn Green When Ready\n\n {client_selector}\n\n**Active Client:**{wrap_with_spaces(active_client_name, prefix_spaces=5)}")
|
240 |
-
|
241 |
-
client_callout_kind = "success" if client is not None else "neutral"
|
242 |
-
return client_callout_kind, client_status
|
243 |
|
|
|
|
|
|
|
|
|
|
|
|
|
244 |
|
245 |
@app.cell
|
246 |
def _(client_callout_kind, client_instantiation_form, client_status, mo):
|
|
|
201 |
|
202 |
|
203 |
@app.cell
|
204 |
+
def client_instantiation(
|
205 |
APIClient,
|
206 |
Credentials,
|
207 |
+
client,
|
208 |
+
client_key,
|
209 |
+
client_options,
|
210 |
+
client_selector,
|
211 |
client_setup,
|
212 |
+
get_key_by_value,
|
213 |
+
mo,
|
214 |
project_id,
|
215 |
space_id,
|
216 |
+
wrap_with_spaces,
|
217 |
wx_api_key,
|
218 |
wx_url,
|
219 |
):
|
220 |
+
### Instantiate the watsonx.ai client
|
221 |
if client_setup:
|
222 |
+
try:
|
223 |
+
wx_credentials = Credentials(url=wx_url, api_key=wx_api_key)
|
224 |
|
225 |
+
project_client = (
|
226 |
+
APIClient(credentials=wx_credentials, project_id=project_id)
|
227 |
+
if project_id
|
228 |
+
else None
|
229 |
+
)
|
230 |
+
|
231 |
+
deployment_client = (
|
232 |
+
APIClient(credentials=wx_credentials, space_id=space_id)
|
233 |
+
if space_id
|
234 |
+
else None
|
235 |
+
)
|
236 |
|
237 |
+
active_client_name = get_key_by_value(client_options, client_key)
|
238 |
+
client_status = mo.md(
|
239 |
+
f"### ✅ Client Instantiation Successful ✅\n\n"
|
240 |
+
f"{client_selector}\n\n"
|
241 |
+
f"**Active Client:**{wrap_with_spaces(active_client_name, prefix_spaces=5)}"
|
242 |
+
)
|
243 |
+
client_callout_kind = "success"
|
244 |
|
245 |
+
except Exception as e:
|
246 |
+
error_message = str(e)
|
247 |
+
client_status = mo.md(
|
248 |
+
f"### ❌ Client Instantiation Failed\n**Error:** {error_message}\n\nCheck your region selection and credentials"
|
249 |
+
)
|
250 |
+
client_callout_kind = "danger"
|
251 |
+
wx_credentials = project_client = deployment_client = None
|
252 |
else:
|
253 |
wx_credentials = project_client = deployment_client = None
|
254 |
+
active_client_name = get_key_by_value(client_options, client_key)
|
255 |
+
client_status = mo.md(
|
256 |
+
f"### Client Instantiation Status will turn Green When Ready\n\n"
|
257 |
+
f"{client_selector}\n\n"
|
258 |
+
f"**Active Client:**{wrap_with_spaces(active_client_name, prefix_spaces=5)}"
|
259 |
+
)
|
260 |
+
client_callout_kind = "neutral"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
261 |
|
262 |
+
return (
|
263 |
+
client_callout_kind,
|
264 |
+
client_status,
|
265 |
+
deployment_client,
|
266 |
+
project_client,
|
267 |
+
)
|
268 |
|
269 |
@app.cell
|
270 |
def _(client_callout_kind, client_instantiation_form, client_status, mo):
|