MilanM commited on
Commit
17baa27
·
verified ·
1 Parent(s): 312bffc

Update main_app.py

Browse files
Files changed (1) hide show
  1. main_app.py +31 -5
main_app.py CHANGED
@@ -19,6 +19,7 @@ app = marimo.App(width="medium")
19
  from ibm_watsonx_ai import APIClient, Credentials
20
  from ibmcloudant.cloudant_v1 import CloudantV1, Document
21
  from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
 
22
  import marimo as mo
23
  import pandas as pd
24
  import requests
@@ -55,7 +56,6 @@ def _(mo):
55
 
56
  @app.cell
57
  def _(os):
58
-
59
  # Set explicit temporary directory
60
  os.environ['TMPDIR'] = '/tmp/notebook_functions'
61
 
@@ -212,11 +212,37 @@ def _(deployment_client, project_client):
212
 
213
 
214
  @app.cell
215
- def _(mo):
216
- template_variants = [
217
- "Base",
218
- "Stream Files to IBM COS [Example]",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
219
  ]
 
 
 
 
 
 
220
  template_variant = mo.ui.dropdown(template_variants, label="Code Template:", value="Base")
221
  return (template_variant,)
222
 
 
19
  from ibm_watsonx_ai import APIClient, Credentials
20
  from ibmcloudant.cloudant_v1 import CloudantV1, Document
21
  from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
22
+ from cloudant_helper_functions import cloudant_retrieve_documents, ensure_database_exists
23
  import marimo as mo
24
  import pandas as pd
25
  import requests
 
56
 
57
  @app.cell
58
  def _(os):
 
59
  # Set explicit temporary directory
60
  os.environ['TMPDIR'] = '/tmp/notebook_functions'
61
 
 
212
 
213
 
214
  @app.cell
215
+ def _():
216
+ cloudant_apikey = os.getenv("CLOUDANT_APIKEY", "")
217
+ cloudant_url = os.getenv("CLOUDANT_URL", "")
218
+ cloudant_db = os.getenv("CLOUDANT_DATABASE", "")
219
+
220
+ authenticator = IAMAuthenticator(cloudant_apikey)
221
+ cloudant = CloudantV1(authenticator=authenticator)
222
+
223
+ cloudant.set_service_url(cloudant_url)
224
+ cloudant.http_client.verify = certifi.where()
225
+ os.environ["REQUESTS_CA_BUNDLE"] = certifi.where()
226
+ return (cloudant,)
227
+
228
+ @app.cell
229
+ def _(cloudant, cloudant_db):
230
+ variant_selectors = cloudant_retrieve_documents(
231
+ client=cloudant,
232
+ db_name=cloudant_db.value,
233
+ selectors={"filename": {"$exists": True}},
234
+ fields=["category"],
235
+ )
236
+
237
+ variant_selectors_list = [
238
+ item["category"] for item in variant_selectors["docs"]
239
  ]
240
+ # variant_selectors_list
241
+ return (variant_selectors_list,)
242
+
243
+ @app.cell
244
+ def _(mo):
245
+ template_variants = variant_selectors_list
246
  template_variant = mo.ui.dropdown(template_variants, label="Code Template:", value="Base")
247
  return (template_variant,)
248