MilanM commited on
Commit
7dfa919
·
verified ·
1 Parent(s): 667310a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -25
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
- wx_credentials = Credentials(url=wx_url,
215
- api_key=wx_api_key)
216
 
217
- project_client = APIClient(credentials=wx_credentials,
218
- project_id=project_id) if project_id else None
 
 
 
 
 
 
 
 
 
219
 
220
- deployment_client = APIClient(credentials=wx_credentials,
221
- space_id=space_id) if space_id else None
 
 
 
 
 
222
 
 
 
 
 
 
 
 
223
  else:
224
  wx_credentials = project_client = deployment_client = None
225
- return deployment_client, project_client
226
-
227
-
228
- @app.cell
229
- def _(
230
- client,
231
- client_key,
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):