Proxy solution to run elegant Web UIs natively inside databricks notebooks.
YOU CAN ONLY USE THIS IN DATABRICKS NOTEBOOKS WITH A RUNNING CLUSTER
FOR SECURE ACCESS PLEASE USE A SINGLE USER CLUSTER (ANYONE WITH ATTACH CAN ACCESS THE UIs)
Easy way to test the following things on a databricks cluster and notebooks
Easy way to test out llm chatbots; look in examples/gradio
This is to support decoupling your UI code from your databricks notebooks. Usually will have a script_path argument instead of directly passing your "app" object. This is convenient for shipping your app outside of a notebook.
DBTunnel provides a proxy layer using asgiproxy fork to support UIs that do not support proxy root paths, etc. It also comes with a simple token based auth provider that only works on databricks to help you get access to user information.
DBTunnel Proxy features:
You must use A10 GPU instances or higher
Please do not use this in production!!
inject_auth
You can pass databricks user auth from your notebook session to any of the frameworks by doing the following:
from dbtunnel import dbtunnel
dbtunnel.<framework>(<script_path>).inject_auth().run()
For example:
from dbtunnel import dbtunnel
dbtunnel.gradio(demo).inject_auth().run()
This exposes the user information via environment variable DATABRICKS_HOST and DATABRICKS_TOKEN.
inject_sql_warehouse
You can pass databricks warehouse auth from your notebook session to any of the frameworks by doing the following:
from dbtunnel import dbtunnel
dbtunnel.<framework>(<script_path>).inject_sql_warehouse().run()
This exposes the warehouse information via environment variable DATABRICKS_HOST, DATABRICKS_TOKEN and DATABRICKS_HTTP_PATH.
inject_env
You can pass custom environment variables from your notebook to any of the frameworks by doing the following:
from dbtunnel import dbtunnel
dbtunnel.<framework>(<script_path>).inject_env(**{
"MY_CUSTOM_ENV": "my_custom_env_value"
}).run()
For example:
from dbtunnel import dbtunnel
dbtunnel.gradio(demo).inject_env(**{
"MY_CUSTOM_ENV": "my_custom_env_value"
}).run()
Alternatively
from dbtunnel import dbtunnel
dbtunnel.gradio(demo).inject_env(MY_CUSTOM_ENV="my_custom_env_value").run()
Keep in mind environment variables need to be keyword arguments!
WARNING: IT WILL BE PUBLICLY AVAILABLE TO ANYONE WITH THE LINK SO DO NOT EXPOSE ANYTHING SENSITIVE
The reason for doing this is to test something with a friend or colleague who is not logged in into databricks. The proxy option requires you to be logged in into databricks.
kill_all_tunnel_sessions=True
Take a look at the full example here streamlit-example-ngrok.py
from dbtunnel import dbtunnel
# again this example is with streamlit but works with any framework
dbtunnel.streamlit("<script_path>").share_to_internet_via_ngrok(
ngrok_api_token="<ngrok api token>",
ngrok_tunnel_auth_token="<ngrok tunnel auth token>"
).run()
# if you need to kill tunnels because you are on free tier:
# again this example is with streamlit but works with any framework
dbtunnel.streamlit("<script_path>").share_to_internet_via_ngrok(
ngrok_api_token="<ngrok api token>",
ngrok_tunnel_auth_token="<ngrok tunnel auth token>",
kill_all_tunnel_sessions=True,
).run()
from dbtunnel import dbtunnel
dbtunnel.kill_port(<port number as int>)
dbtunnel is not developed, endorsed not supported by Databricks. It is provided as-is; no warranty is derived from using this package. For more details, please refer to the license.