Update main_app.py
Browse files- main_app.py +68 -65
main_app.py
CHANGED
|
@@ -91,34 +91,19 @@ def _(os):
|
|
| 91 |
|
| 92 |
@app.cell
|
| 93 |
def _(client_instantiation_form, os):
|
| 94 |
-
|
| 95 |
-
client_setup = client_instantiation_form.value
|
| 96 |
-
else:
|
| 97 |
-
client_setup = None
|
| 98 |
|
| 99 |
### Extract Credential Variables:
|
| 100 |
-
if client_setup
|
| 101 |
-
wx_url = client_setup["wx_region"]
|
| 102 |
-
wx_api_key = client_setup["wx_api_key"].strip()
|
| 103 |
-
os.environ["WATSONX_APIKEY"] = wx_api_key
|
| 104 |
-
|
| 105 |
-
if client_setup["project_id"] is not None:
|
| 106 |
-
project_id = client_setup["project_id"].strip()
|
| 107 |
-
else:
|
| 108 |
-
project_id = None
|
| 109 |
-
|
| 110 |
-
if client_setup["space_id"] is not None:
|
| 111 |
-
space_id = client_setup["space_id"].strip()
|
| 112 |
-
else:
|
| 113 |
-
space_id = None
|
| 114 |
|
|
|
|
|
|
|
| 115 |
else:
|
| 116 |
os.environ["WATSONX_APIKEY"] = ""
|
| 117 |
-
project_id = None
|
| 118 |
-
space_id = None
|
| 119 |
-
wx_api_key = None
|
| 120 |
-
wx_url = None
|
| 121 |
-
|
| 122 |
return client_setup, project_id, space_id, wx_api_key, wx_url
|
| 123 |
|
| 124 |
|
|
@@ -196,41 +181,52 @@ def _(
|
|
| 196 |
):
|
| 197 |
### Instantiate the watsonx.ai client
|
| 198 |
if client_setup:
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
else:
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
task_credentials_details = None
|
| 231 |
-
client = None
|
| 232 |
|
| 233 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
|
| 235 |
|
| 236 |
@app.cell
|
|
@@ -641,6 +637,7 @@ def _(ast, template, function_editor, mo, os):
|
|
| 641 |
@app.cell
|
| 642 |
def _(template):
|
| 643 |
dependencies = template["dependencies"]
|
|
|
|
| 644 |
added_yaml_template = f"""dependencies:
|
| 645 |
- pip
|
| 646 |
- pip:
|
|
@@ -713,23 +710,27 @@ def _(mo, yaml_template, dependency_pack_name):
|
|
| 713 |
placeholder="Python Package for...",
|
| 714 |
label="Package Extension Name:",
|
| 715 |
kind="text",
|
| 716 |
-
value=f"
|
|
|
|
| 717 |
),
|
| 718 |
software_spec_name=mo.ui.text(
|
| 719 |
placeholder="Software Spec Name",
|
| 720 |
label="Custom Software Spec Name:",
|
| 721 |
kind="text",
|
| 722 |
-
value=f"
|
|
|
|
| 723 |
),
|
| 724 |
package_description=mo.ui.text_area(
|
| 725 |
placeholder="Write a description for your package.",
|
| 726 |
label="Package Description:",
|
| 727 |
value=" ",
|
|
|
|
| 728 |
),
|
| 729 |
software_spec_description=mo.ui.text_area(
|
| 730 |
placeholder="Write a description for your software spec.",
|
| 731 |
label="Software Spec Description:",
|
| 732 |
value=" ",
|
|
|
|
| 733 |
),
|
| 734 |
package_type=mo.ui.dropdown(
|
| 735 |
pkg_types, label="Select your package type:", value="Conda Yaml"
|
|
@@ -754,7 +755,8 @@ def _(mo):
|
|
| 754 |
)
|
| 755 |
.batch(
|
| 756 |
package_list=mo.ui.text_area(
|
| 757 |
-
placeholder="Add packages as a comma separated list (with or without versions)."
|
|
|
|
| 758 |
),
|
| 759 |
return_full_list=mo.ui.checkbox(
|
| 760 |
value=False,
|
|
@@ -823,7 +825,7 @@ def _(client, create_yaml_tempfile, package_meta, uuid):
|
|
| 823 |
pack_suffix = str(uuid.uuid4())[:4]
|
| 824 |
pack_name = package_meta.value["package_name"]
|
| 825 |
pe_metadata = {
|
| 826 |
-
client.package_extensions.ConfigurationMetaNames.NAME: f"{pack_name}_{pack_suffix}",
|
| 827 |
client.package_extensions.ConfigurationMetaNames.TYPE: package_meta.value[
|
| 828 |
"package_type"
|
| 829 |
],
|
|
@@ -1079,7 +1081,7 @@ def _(
|
|
| 1079 |
ss_name = package_meta.value["software_spec_name"]
|
| 1080 |
|
| 1081 |
ss_metadata = {
|
| 1082 |
-
client.software_specifications.ConfigurationMetaNames.NAME: f"{ss_name}_{ss_suffix}",
|
| 1083 |
client.software_specifications.ConfigurationMetaNames.DESCRIPTION: package_meta.value[
|
| 1084 |
"software_spec_description"
|
| 1085 |
],
|
|
@@ -1722,9 +1724,10 @@ def _(client, mo, pd, upload_button, uuid):
|
|
| 1722 |
uuid_suffix = str(uuid.uuid4())[:4]
|
| 1723 |
|
| 1724 |
deployment_name = mo.ui.text(
|
| 1725 |
-
value=f"{uploaded_function_name.value}
|
| 1726 |
label="Deployment Name:",
|
| 1727 |
placeholder="<Must be completely unique>",
|
|
|
|
| 1728 |
)
|
| 1729 |
else:
|
| 1730 |
hw_df = pd.DataFrame(data=[["ID", "Activate client."]], columns=["ID", "VALUE"])
|
|
@@ -1770,16 +1773,16 @@ def _(
|
|
| 1770 |
deployment_type.value == "Online (Function Endpoint)"
|
| 1771 |
): # Changed from "Online (Function Endpoint)"
|
| 1772 |
deployment_props = {
|
| 1773 |
-
client.deployments.ConfigurationMetaNames.NAME: deployment_name.value,
|
| 1774 |
client.deployments.ConfigurationMetaNames.ONLINE: {},
|
| 1775 |
client.deployments.ConfigurationMetaNames.HARDWARE_SPEC: {
|
| 1776 |
"id": selected_hw_config
|
| 1777 |
},
|
| 1778 |
-
client.deployments.ConfigurationMetaNames.SERVING_NAME: deployment_name.value,
|
| 1779 |
}
|
| 1780 |
else: # "Runnable Job" instead of "Batch (Runnable Jobs)"
|
| 1781 |
deployment_props = {
|
| 1782 |
-
client.deployments.ConfigurationMetaNames.NAME: deployment_name.value,
|
| 1783 |
client.deployments.ConfigurationMetaNames.BATCH: {},
|
| 1784 |
client.deployments.ConfigurationMetaNames.HARDWARE_SPEC: {
|
| 1785 |
"id": selected_hw_config
|
|
|
|
| 91 |
|
| 92 |
@app.cell
|
| 93 |
def _(client_instantiation_form, os):
|
| 94 |
+
client_setup = client_instantiation_form.value or None
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
### Extract Credential Variables:
|
| 97 |
+
if client_setup:
|
| 98 |
+
wx_url = client_setup["wx_region"] if client_setup["wx_region"] else "EU"
|
| 99 |
+
wx_api_key = client_setup["wx_api_key"].strip() if client_setup["wx_api_key"] else None
|
| 100 |
+
os.environ["WATSONX_APIKEY"] = wx_api_key or ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
+
project_id = client_setup["project_id"].strip() if client_setup["project_id"] else None
|
| 103 |
+
space_id = client_setup["space_id"].strip() if client_setup["space_id"] else None
|
| 104 |
else:
|
| 105 |
os.environ["WATSONX_APIKEY"] = ""
|
| 106 |
+
project_id = space_id = wx_api_key = wx_url = None
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
return client_setup, project_id, space_id, wx_api_key, wx_url
|
| 108 |
|
| 109 |
|
|
|
|
| 181 |
):
|
| 182 |
### Instantiate the watsonx.ai client
|
| 183 |
if client_setup:
|
| 184 |
+
wx_credentials = Credentials(url=wx_url, api_key=wx_api_key)
|
| 185 |
+
|
| 186 |
+
try:
|
| 187 |
+
project_client = (
|
| 188 |
+
APIClient(credentials=wx_credentials, project_id=project_id)
|
| 189 |
+
if project_id
|
| 190 |
+
else None
|
| 191 |
+
)
|
| 192 |
+
except Exception:
|
| 193 |
+
project_client = None
|
| 194 |
+
|
| 195 |
+
try:
|
| 196 |
+
deployment_client = (
|
| 197 |
+
APIClient(credentials=wx_credentials, space_id=space_id)
|
| 198 |
+
if space_id
|
| 199 |
+
else None
|
| 200 |
+
)
|
| 201 |
+
except Exception:
|
| 202 |
+
deployment_client = None
|
| 203 |
+
|
| 204 |
+
try:
|
| 205 |
+
task_credentials_details = (
|
| 206 |
+
setup_task_credentials(project_client)
|
| 207 |
+
if project_client
|
| 208 |
+
else setup_task_credentials(deployment_client)
|
| 209 |
+
if deployment_client
|
| 210 |
+
else None
|
| 211 |
+
)
|
| 212 |
+
instantiation_success = True
|
| 213 |
+
instantiation_error = None
|
| 214 |
+
except Exception as e:
|
| 215 |
+
instantiation_success = False
|
| 216 |
+
instantiation_error = str(e)
|
| 217 |
+
task_credentials_details = None
|
| 218 |
else:
|
| 219 |
+
wx_credentials = project_client = deployment_client = task_credentials_details = None
|
| 220 |
+
instantiation_success = None
|
| 221 |
+
instantiation_error = None
|
|
|
|
|
|
|
| 222 |
|
| 223 |
+
return (
|
| 224 |
+
deployment_client,
|
| 225 |
+
instantiation_error,
|
| 226 |
+
instantiation_success,
|
| 227 |
+
project_client,
|
| 228 |
+
task_credentials_details
|
| 229 |
+
)
|
| 230 |
|
| 231 |
|
| 232 |
@app.cell
|
|
|
|
| 637 |
@app.cell
|
| 638 |
def _(template):
|
| 639 |
dependencies = template["dependencies"]
|
| 640 |
+
dependencies_string = ', '.join(dependencies)
|
| 641 |
added_yaml_template = f"""dependencies:
|
| 642 |
- pip
|
| 643 |
- pip:
|
|
|
|
| 710 |
placeholder="Python Package for...",
|
| 711 |
label="Package Extension Name:",
|
| 712 |
kind="text",
|
| 713 |
+
value=f"{dependency_pack_name}_custom_python_pack",
|
| 714 |
+
max_length=int(31)
|
| 715 |
),
|
| 716 |
software_spec_name=mo.ui.text(
|
| 717 |
placeholder="Software Spec Name",
|
| 718 |
label="Custom Software Spec Name:",
|
| 719 |
kind="text",
|
| 720 |
+
value=f"{dependency_pack_name}_python_sw_spec",
|
| 721 |
+
max_length=int(31)
|
| 722 |
),
|
| 723 |
package_description=mo.ui.text_area(
|
| 724 |
placeholder="Write a description for your package.",
|
| 725 |
label="Package Description:",
|
| 726 |
value=" ",
|
| 727 |
+
max_length=int(256)
|
| 728 |
),
|
| 729 |
software_spec_description=mo.ui.text_area(
|
| 730 |
placeholder="Write a description for your software spec.",
|
| 731 |
label="Software Spec Description:",
|
| 732 |
value=" ",
|
| 733 |
+
max_length=int(256)
|
| 734 |
),
|
| 735 |
package_type=mo.ui.dropdown(
|
| 736 |
pkg_types, label="Select your package type:", value="Conda Yaml"
|
|
|
|
| 755 |
)
|
| 756 |
.batch(
|
| 757 |
package_list=mo.ui.text_area(
|
| 758 |
+
placeholder="Add packages as a comma separated list (with or without versions).",
|
| 759 |
+
value=str(dependencies_string)
|
| 760 |
),
|
| 761 |
return_full_list=mo.ui.checkbox(
|
| 762 |
value=False,
|
|
|
|
| 825 |
pack_suffix = str(uuid.uuid4())[:4]
|
| 826 |
pack_name = package_meta.value["package_name"]
|
| 827 |
pe_metadata = {
|
| 828 |
+
client.package_extensions.ConfigurationMetaNames.NAME: f"{pack_name}_{pack_suffix}"[:36],
|
| 829 |
client.package_extensions.ConfigurationMetaNames.TYPE: package_meta.value[
|
| 830 |
"package_type"
|
| 831 |
],
|
|
|
|
| 1081 |
ss_name = package_meta.value["software_spec_name"]
|
| 1082 |
|
| 1083 |
ss_metadata = {
|
| 1084 |
+
client.software_specifications.ConfigurationMetaNames.NAME: f"{ss_name}_{ss_suffix}"[:36],
|
| 1085 |
client.software_specifications.ConfigurationMetaNames.DESCRIPTION: package_meta.value[
|
| 1086 |
"software_spec_description"
|
| 1087 |
],
|
|
|
|
| 1724 |
uuid_suffix = str(uuid.uuid4())[:4]
|
| 1725 |
|
| 1726 |
deployment_name = mo.ui.text(
|
| 1727 |
+
value=f"{uploaded_function_name.value}_{uuid_suffix}_dep"[:36],
|
| 1728 |
label="Deployment Name:",
|
| 1729 |
placeholder="<Must be completely unique>",
|
| 1730 |
+
max_length=int(31)
|
| 1731 |
)
|
| 1732 |
else:
|
| 1733 |
hw_df = pd.DataFrame(data=[["ID", "Activate client."]], columns=["ID", "VALUE"])
|
|
|
|
| 1773 |
deployment_type.value == "Online (Function Endpoint)"
|
| 1774 |
): # Changed from "Online (Function Endpoint)"
|
| 1775 |
deployment_props = {
|
| 1776 |
+
client.deployments.ConfigurationMetaNames.NAME: str(deployment_name.value)[:36],
|
| 1777 |
client.deployments.ConfigurationMetaNames.ONLINE: {},
|
| 1778 |
client.deployments.ConfigurationMetaNames.HARDWARE_SPEC: {
|
| 1779 |
"id": selected_hw_config
|
| 1780 |
},
|
| 1781 |
+
client.deployments.ConfigurationMetaNames.SERVING_NAME: str(deployment_name.value)[:36],
|
| 1782 |
}
|
| 1783 |
else: # "Runnable Job" instead of "Batch (Runnable Jobs)"
|
| 1784 |
deployment_props = {
|
| 1785 |
+
client.deployments.ConfigurationMetaNames.NAME: str(deployment_name.value)[:36],
|
| 1786 |
client.deployments.ConfigurationMetaNames.BATCH: {},
|
| 1787 |
client.deployments.ConfigurationMetaNames.HARDWARE_SPEC: {
|
| 1788 |
"id": selected_hw_config
|