Skip to content

Commit

Permalink
Merge pull request #75 from databricks-industry-solutions/bugfix/runme
Browse files Browse the repository at this point in the history
New RUNME! 100% Serverless + OHIF in lakehouse APP deploy
  • Loading branch information
calreynolds authored Nov 18, 2024
2 parents e614f69 + 90d4003 commit dca5b92
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 48 deletions.
13 changes: 8 additions & 5 deletions 00-README.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# MAGIC - Uses proven `gdcm`, `python-gdcm` & `pydicom` python packages & C++ libraries
# MAGIC - Simple composing and extension into De-Identification and Deep Learing
# MAGIC <!-- -->
# MAGIC
# MAGIC
# MAGIC The `dbx.pixels` solution accelerator turns DICOM images into SQL data

# COMMAND ----------
Expand All @@ -28,17 +28,20 @@
# COMMAND ----------

# MAGIC %md ## Licensing
# MAGIC
# MAGIC &copy; 2022 Databricks, Inc. All rights reserved. The source in this notebook is provided subject to the Databricks License [https://databricks.com/db-license-source]. All included or referenced third party libraries are subject to the licenses set forth below.
# MAGIC
# MAGIC
# MAGIC &copy; 2024 Databricks, Inc. All rights reserved. The source in this notebook is provided subject to the Databricks License [https://databricks.com/db-license-source]. All included or referenced third party libraries are subject to the licenses set forth below.
# MAGIC
# MAGIC | library | purpose | license | source |
# MAGIC |----------------------|-------------------------------------|-------------------------------|---------------------------------------------------------|
# MAGIC | dbx.pixels | Scale out image processong Spark | Databricks | https://github.com/databricks-industry-solutions/pixels |
# MAGIC | pydicom | Reading Dicom file wrapper | MIT | https://github.com/pydicom/pydicom |
# MAGIC | python-gdcm | Install gdcm C++ libraries | Apache Software License (BSD) | https://github.com/tfmoraes/python-gdcm |
# MAGIC | gdcm | Parse Dicom files. | BSD | https://gdcm.sourceforge.net/wiki/index.php/Main_Page |
# MAGIC | gdcm | Parse Dicom files | BSD | https://gdcm.sourceforge.net/wiki/index.php/Main_Page |
# MAGIC | s3fs | Resolve s3:// paths | BSD 3-Clause | https://github.com/fsspec/s3fs |
# MAGIC | pandas | Pandas UDFs | BSD License (BSD-3-Clause) | https://github.com/pandas-dev/pandas |
# MAGIC | OHIF Viewer | Medical image viewer | MIT | https://github.com/OHIF/Viewers |
# MAGIC | MONAILabel | Intelligent open source image labeling and learning tool | Apache-2.0 license | https://github.com/Project-MONAI/MONAILabel |
# MAGIC

# COMMAND ----------

Expand Down
26 changes: 16 additions & 10 deletions 07-OHIF-Lakehouse-App.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# COMMAND ----------

# MAGIC %pip install --upgrade databricks-sdk -q
# MAGIC %pip install --upgrade databricks-sdk==0.36.0 -q
# MAGIC dbutils.library.restartPython()

# COMMAND ----------
Expand All @@ -26,7 +26,7 @@
init_env()

app_name = "pixels-ohif-viewer"
serving_endpoint = "pixels-monai-uc"
serving_endpoint_name = "pixels-monai-uc"

w = WorkspaceClient()

Expand Down Expand Up @@ -70,25 +70,31 @@
.replace("{PIXELS_TABLE}", table)
)

resources = []

sql_resource = AppResource(
name="sql_warehouse",
sql_warehouse=AppResourceSqlWarehouse(
id=sql_warehouse_id,
permission=AppResourceSqlWarehouseSqlWarehousePermission.CAN_USE
)
)

serving_endpoint = AppResource(
name="serving_endpoint",
serving_endpoint=AppResourceServingEndpoint(
name=serving_endpoint,
permission=AppResourceServingEndpointServingEndpointPermission.CAN_QUERY
resources.append(sql_resource)

if serving_endpoint_name in [endpoint.name for endpoint in w.serving_endpoints.list()]:
serving_endpoint = AppResource(
name="serving_endpoint",
serving_endpoint=AppResourceServingEndpoint(
name=serving_endpoint_name,
permission=AppResourceServingEndpointServingEndpointPermission.CAN_QUERY
)
)
)
resources.append(serving_endpoint)


print(f"Creating Lakehouse App with name {app_name}, this step will require few minutes to complete")

app_created = w.apps.create_and_wait(name=app_name, resources=[sql_resource, serving_endpoint])
app_created = w.apps.create_and_wait(name=app_name, resources=resources)
app_deploy = w.apps.deploy_and_wait(app_name=app_name, source_code_path=lha_path)

print(app_deploy.status.message)
Expand Down
47 changes: 18 additions & 29 deletions RUNME.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
# Databricks notebook source
# MAGIC %md This notebook sets up the companion cluster(s) to run the solution accelerator. It also creates the Workflow to illustrate the order of execution. Happy exploring!
# MAGIC 🎉
# MAGIC
# MAGIC
# MAGIC **Steps**
# MAGIC 1. Simply attach this notebook to a cluster and hit `Run all` for this notebook. A multi-step job and the clusters used in the job will be created for you and hyperlinks are printed on the last block of the notebook.
# MAGIC
# MAGIC
# MAGIC 2. Run the accelerator notebooks: Feel free to explore the multi-step job page and **run the Workflow**, or **run the notebooks interactively** with the cluster to see how this solution accelerator executes.
# MAGIC
# MAGIC
# MAGIC 2a. **Run the Workflow**: Navigate to the Workflow link and hit the `Run Now` 💥.
# MAGIC
# MAGIC 2b. **Run the notebooks interactively**: Attach the notebook with the cluster(s) created and execute as described in the `job_json['tasks']` below.
# MAGIC
# MAGIC
# MAGIC **Prerequisites**
# MAGIC 1. You need to have cluster creation permissions in this workspace.
# MAGIC
# MAGIC
# MAGIC 2. In case the environment has cluster-policies that interfere with automated deployment, you may need to manually create the cluster in accordance with the workspace cluster policy. The `job_json` definition below still provides valuable information about the configuration these series of notebooks should run with.
# MAGIC
# MAGIC
# MAGIC **Notes**
# MAGIC 1. The pipelines, workflows and clusters created in this script are not user-specific. Keep in mind that rerunning this script again after modification resets them for other users too.
# MAGIC
# MAGIC
# MAGIC 2. If the job execution fails, please confirm that you have set up other environment dependencies as specified in the accelerator notebooks. Accelerators may require the user to set up additional cloud infra or secrets to manage credentials.

# COMMAND ----------

# DBTITLE 0,Install util packages
# MAGIC %pip install git+https://github.com/databricks-academy/[email protected] git+https://github.com/databricks-industry-solutions/notebook-solution-companion@safe-print-html --quiet
# MAGIC %pip install git+https://github.com/databricks-academy/[email protected] git+https://github.com/databricks-industry-solutions/notebook-solution-companion@serverless --quiet

# COMMAND ----------

Expand All @@ -42,14 +42,12 @@
},
"tasks": [
{
"job_cluster_key": "pixels_cluster",
"notebook_task": {
"notebook_path": f"00-README"
},
"task_key": "00-README"
},
{
"job_cluster_key": "pixels_cluster",
"notebook_task": {
"notebook_path": f"01-dcm-demo"
},
Expand All @@ -61,36 +59,27 @@
]
},
{
"job_cluster_key": "pixels_cluster",
"notebook_task": {
"notebook_path": f"02-dcm-browser"
"notebook_path": f"07-OHIF-Lakehouse-App"
},
"task_key": "02-dcm-browser",
"task_key": "07-OHIF-Lakehouse-App",
"depends_on": [
{
"task_key": "01-dcm-demo"
}
]
}
],
"job_clusters": [
"parameters": [
{
"job_cluster_key": "pixels_cluster",
"new_cluster": {
"spark_version": "14.3.x-scala2.12",
"spark_conf": {
"spark.databricks.delta.formatCheck.enabled": "false"
},
"num_workers": 8,
"node_type_id": {"AWS": "c5d.2xlarge", "MSA": "Standard_DS4_v2", "GCP": "n1-highmem-4"},
"custom_tags": {
"usage": "solacc_testing",
"group": "HLS",
"accelerator": "pixels"
},
}
"name": "table",
"default": "main.pixel_solacc.object_catalog"
},
{
"name": "volume",
"default": "main.pixel_solacc.pixels_volume"
}
]
]
}

# COMMAND ----------
Expand Down
10 changes: 8 additions & 2 deletions config/proxy_prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ def init_widgets(show_volume=False):
dbutils.widgets.text("sqlWarehouseID", "", label="2.0 SQL Warehouse")
sql_warehouse_id = dbutils.widgets.get("sqlWarehouseID")

if sql_warehouse_id == "":
sql_warehouse = w.warehouses.list()[0]
sql_warehouse_id = sql_warehouse.id
dbutils.widgets.text("sqlWarehouseID", sql_warehouse_id, label="2.0 SQL Warehouse")
print(f"SQL Warehouse is mandatory, taking the first available: '{sql_warehouse.name}'")

if show_volume:
dbutils.widgets.text("volume", "main.pixels_solacc.pixels_volume", label="3.0 Catalog Schema Volume where pixel volumes are stored into")
volume = dbutils.widgets.get("volume")
Expand Down Expand Up @@ -47,10 +53,10 @@ def init_env():
else:
wh = w.warehouses.get(id=sql_warehouse_id)
print(f"Using '{wh.as_dict()['name']}' as SQL Warehouse")

os.environ["DATABRICKS_TOKEN"] = ctx.apiToken
os.environ["DATABRICKS_WAREHOUSE_ID"] = sql_warehouse_id
os.environ["DATABRICKS_HOST"] = f"https://{ctx.browserHostName}"
os.environ["DATABRICKS_HOST"] = ctx.apiUrl
os.environ["DATABRICKS_PIXELS_TABLE"] = table

# COMMAND ----------
Expand Down
2 changes: 1 addition & 1 deletion config/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# DBTITLE 1,Collect Input Parameters
def init_widgets():
dbutils.widgets.text("path", "s3://hls-eng-data-public/dicom/ddsm/benigns_2*.zip", label="1.0 Path to directory tree containing files. /dbfs , /Volumes/ or s3:// supported")
dbutils.widgets.text("path", "s3://hls-eng-data-public/dicom/ddsm/benigns_21*.zip", label="1.0 Path to directory tree containing files. /dbfs , /Volumes/ or s3:// supported")
dbutils.widgets.text("table", "main.pixels_solacc.object_catalog", label="2.0 Catalog Schema Table to store object metadata into")
dbutils.widgets.text("volume", "main.pixels_solacc.pixels_volume", label="3.0 Catalog Schema Volume to store checkpoints and unzipped files")
dbutils.widgets.dropdown("mode",defaultValue="append",choices=["overwrite","append"], label="4.0 Update mode on object metadata table")
Expand Down
6 changes: 5 additions & 1 deletion dbx/pixels/resources/lakehouse_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@

table = os.environ["DATABRICKS_PIXELS_TABLE"]
warehouse_id = os.environ["DATABRICKS_WAREHOUSE_ID"]
serving_endpoint = os.environ["MONAI_SERVING_ENDPOINT"]

if "MONAI_SERVING_ENDPOINT" in os.environ:
serving_endpoint = os.environ["MONAI_SERVING_ENDPOINT"]
else:
serving_endpoint = ""

path = Path(dbx.pixels.__file__).parent
ohif_path = f"{path}/resources/ohif"
Expand Down

0 comments on commit dca5b92

Please sign in to comment.