Update main_app.py
Browse files- main_app.py +22 -74
main_app.py
CHANGED
@@ -1,14 +1,31 @@
|
|
1 |
import marimo
|
2 |
|
3 |
-
__generated_with = "0.
|
4 |
app = marimo.App(width="medium")
|
5 |
|
6 |
|
7 |
-
@app.
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
import marimo as mo
|
10 |
-
import
|
11 |
-
|
|
|
|
|
|
|
|
|
12 |
|
13 |
|
14 |
@app.function
|
@@ -38,29 +55,6 @@ def _(mo):
|
|
38 |
|
39 |
@app.cell
|
40 |
def _(os):
|
41 |
-
### Imports
|
42 |
-
from typing import Any, Dict, List, Optional, Pattern, Set, Union, Tuple
|
43 |
-
from ibm_watsonx_ai import APIClient, Credentials
|
44 |
-
from pathlib import Path
|
45 |
-
import importlib.util
|
46 |
-
import pandas as pd
|
47 |
-
import mimetypes
|
48 |
-
import requests
|
49 |
-
import zipfile
|
50 |
-
import polars
|
51 |
-
import urllib3
|
52 |
-
import tempfile
|
53 |
-
import importlib.util
|
54 |
-
import base64
|
55 |
-
import certifi
|
56 |
-
import uuid
|
57 |
-
import time
|
58 |
-
import json
|
59 |
-
import sys
|
60 |
-
import ssl
|
61 |
-
import ast
|
62 |
-
import io
|
63 |
-
import re
|
64 |
|
65 |
# Set explicit temporary directory
|
66 |
os.environ['TMPDIR'] = '/tmp/notebook_functions'
|
@@ -71,14 +65,6 @@ def _(os):
|
|
71 |
# Make sure Python's tempfile module also uses this directory
|
72 |
tempfile.tempdir = '/tmp/notebook_functions'
|
73 |
|
74 |
-
def get_iam_token(api_key):
|
75 |
-
return requests.post(
|
76 |
-
'https://iam.cloud.ibm.com/identity/token',
|
77 |
-
headers={'Content-Type': 'application/x-www-form-urlencoded'},
|
78 |
-
data={'grant_type': 'urn:ibm:params:oauth:grant-type:apikey', 'apikey': api_key},
|
79 |
-
verify=certifi.where()
|
80 |
-
).json()['access_token']
|
81 |
-
|
82 |
def setup_task_credentials(client):
|
83 |
# Get existing task credentials
|
84 |
existing_credentials = client.task_credentials.get_details()
|
@@ -92,37 +78,9 @@ def _(os):
|
|
92 |
# Store new credentials
|
93 |
return client.task_credentials.store()
|
94 |
|
95 |
-
def get_cred_value(key, creds_var_name="baked_in_creds", default=""): ### Helper for working with preset credentials
|
96 |
-
"""
|
97 |
-
Helper function to safely get a value from a credentials dictionary.
|
98 |
-
|
99 |
-
Args:
|
100 |
-
key: The key to look up in the credentials dictionary.
|
101 |
-
creds_var_name: The variable name of the credentials dictionary.
|
102 |
-
default: The default value to return if the key is not found.
|
103 |
-
|
104 |
-
Returns:
|
105 |
-
The value from the credentials dictionary if it exists and contains the key,
|
106 |
-
otherwise returns the default value.
|
107 |
-
"""
|
108 |
-
# Check if the credentials variable exists in globals
|
109 |
-
if creds_var_name in globals():
|
110 |
-
creds_dict = globals()[creds_var_name]
|
111 |
-
if isinstance(creds_dict, dict) and key in creds_dict:
|
112 |
-
return creds_dict[key]
|
113 |
-
return default
|
114 |
return (
|
115 |
-
APIClient,
|
116 |
-
Credentials,
|
117 |
-
ast,
|
118 |
-
get_iam_token,
|
119 |
-
importlib,
|
120 |
-
json,
|
121 |
-
pd,
|
122 |
setup_task_credentials,
|
123 |
-
sys,
|
124 |
tempfile,
|
125 |
-
uuid,
|
126 |
)
|
127 |
|
128 |
|
@@ -157,16 +115,6 @@ def _(client_instantiation_form, os):
|
|
157 |
wx_url = None
|
158 |
return client_setup, project_id, space_id, wx_api_key, wx_url
|
159 |
|
160 |
-
|
161 |
-
@app.cell
|
162 |
-
def _(client_setup, get_iam_token, wx_api_key):
|
163 |
-
if client_setup and wx_api_key is not None:
|
164 |
-
token = get_iam_token(wx_api_key)
|
165 |
-
else:
|
166 |
-
token = None
|
167 |
-
return
|
168 |
-
|
169 |
-
|
170 |
@app.cell
|
171 |
def _(mo):
|
172 |
### Credentials for the watsonx.ai SDK client
|
|
|
1 |
import marimo
|
2 |
|
3 |
+
__generated_with = "0.14.12"
|
4 |
app = marimo.App(width="medium")
|
5 |
|
6 |
|
7 |
+
@app.setup:
|
8 |
+
import marimo as mo
|
9 |
+
import ast, base64, glob, io, json, mimetypes, os, re, tempfile, time, zipfile
|
10 |
+
from typing import Any, Dict, List, Optional, Pattern, Union, Callable, Set, Tuple
|
11 |
+
from datetime import datetime
|
12 |
+
from pathlib import Path
|
13 |
+
import importlib.util
|
14 |
+
import urllib3, uuid, sys, ssl
|
15 |
+
import json
|
16 |
+
import ast
|
17 |
+
|
18 |
+
from dotenv import load_dotenv
|
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
|
25 |
+
import certifi
|
26 |
+
|
27 |
+
load_dotenv()
|
28 |
+
|
29 |
|
30 |
|
31 |
@app.function
|
|
|
55 |
|
56 |
@app.cell
|
57 |
def _(os):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
# Set explicit temporary directory
|
60 |
os.environ['TMPDIR'] = '/tmp/notebook_functions'
|
|
|
65 |
# Make sure Python's tempfile module also uses this directory
|
66 |
tempfile.tempdir = '/tmp/notebook_functions'
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
def setup_task_credentials(client):
|
69 |
# Get existing task credentials
|
70 |
existing_credentials = client.task_credentials.get_details()
|
|
|
78 |
# Store new credentials
|
79 |
return client.task_credentials.store()
|
80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
return (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
setup_task_credentials,
|
|
|
83 |
tempfile,
|
|
|
84 |
)
|
85 |
|
86 |
|
|
|
115 |
wx_url = None
|
116 |
return client_setup, project_id, space_id, wx_api_key, wx_url
|
117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
@app.cell
|
119 |
def _(mo):
|
120 |
### Credentials for the watsonx.ai SDK client
|