Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions giskard/client/giskard_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from giskard.client.python_utils import EXCLUDED_PYLIBS, format_pylib_extras, warning
from giskard.core.core import SMT, DatasetMeta, ModelMeta, TestFunctionMeta
from giskard.utils.analytics_collector import analytics, anonymize
from giskard.utils.environment_detector import COLAB, EnvironmentDetector

UNKNOWN_ERROR = "No details or messages available."

Expand Down Expand Up @@ -151,6 +152,8 @@ def __init__(self, url: str, key: str, hf_token: str = None):

self._session.auth = BearerAuth(key)

self._environment = EnvironmentDetector().detect()

if hf_token:
self._session.cookies["spaces-jwt"] = hf_token

Expand Down Expand Up @@ -190,7 +193,13 @@ def get_project(self, project_key: str) -> Project:
response = self._session.get("project", params={"key": project_key}).json()
return Project(self._session, response["key"], response["id"])

def initialize_kernel(self, project_key: str, exact_deps: bool = False, excludes: List[str] = EXCLUDED_PYLIBS):
def initialize_kernel(
self,
project_key: str,
exact_deps: bool = False,
excludes: List[str] = EXCLUDED_PYLIBS,
only_giskard: bool = False,
):
python_version = f"{sys.version_info[0]}.{sys.version_info[1]}"
kernel_name = f"{project_key}_kernel"

Expand All @@ -207,7 +216,7 @@ def initialize_kernel(self, project_key: str, exact_deps: bool = False, excludes
frozen_dependencies = [
f"{dist.name}{format_pylib_extras(dist.name) if exact_deps or dist.name == 'giskard' else ''}=={dist.version}"
for dist in importlib_metadata.distributions()
if dist.name not in excludes
if dist.name not in excludes and (not only_giskard or dist.name == "giskard")
]

existing_kernel = next((kernel for kernel in kernels if kernel["name"] == kernel_name), None)
Expand Down Expand Up @@ -291,7 +300,14 @@ def create_project(self, project_key: str, name: str, description: str = None, k
)

if kernel_name is None:
kernel_name = self.initialize_kernel(project_key)
is_colab = COLAB in self._environment
kernel_name = self.initialize_kernel(project_key, only_giskard=is_colab)
if is_colab:
print(
f"Kernel '{kernel_name}' is created on your Giskard hub."
"We are initializing the environment with only giskard, since you are in Colab."
"Please edit the dependencies in the kernel to align with your environment for model execution."
)

try:
# TODO(Bazire) : use typed object for validation here
Expand Down
60 changes: 37 additions & 23 deletions giskard/utils/environment_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,35 @@ def enum(**enums):
)


DOCKER_DEV = "docker-dev-mode"
DATABRICKS = "databricks"
VSCODE = "vscode"
AZURE = "azure"
AZUREML = "azureml"
KAGGLE = "kaggle"
SAGEMAKER = "sagemaker"
BINDER = "binder"
COLAB = "colab"
AZURESYNAPSE = "azuresynapse"
IPYTHON = "ipython"
IPYTHON_ZMQ = "ipython-zmq"


def is_cloud_env(detected):
non_cloud_env = [
"ipython-zmq",
"ipython",
"vscode",
IPYTHON_ZMQ,
IPYTHON,
VSCODE,
]
cloud_env = [
"databricks",
"azure",
"azureml",
"kaggle",
"sagemaker",
"binder",
"colab",
"azuresynapse",
DATABRICKS,
AZURE,
AZUREML,
KAGGLE,
SAGEMAKER,
BINDER,
COLAB,
AZURESYNAPSE,
]
if len(set(cloud_env).intersection(detected)) != 0 and len(set(non_cloud_env).intersection(detected)) == 0:
return ENV_DETECTED.CLOUD
Expand All @@ -142,18 +156,18 @@ def is_cloud_env(detected):
class EnvironmentDetector:
def __init__(self):
self.checks = {
"docker-dev-mode": _is_docker_development_mode,
"databricks": _detect_databricks,
"vscode": _detect_vscode,
"azure": _detect_azure_notebook,
"azureml": _detect_azureml,
"kaggle": _detect_kaggle,
"sagemaker": _detect_sagemaker,
"binder": _detect_binder,
"colab": _detect_colab,
"ipython-zmq": _detect_ipython_zmq,
"ipython": _detect_ipython,
"azuresynapse": _detect_azure_synapse,
DOCKER_DEV: _is_docker_development_mode,
DATABRICKS: _detect_databricks,
VSCODE: _detect_vscode,
AZURE: _detect_azure_notebook,
AZUREML: _detect_azureml,
KAGGLE: _detect_kaggle,
SAGEMAKER: _detect_sagemaker,
BINDER: _detect_binder,
COLAB: _detect_colab,
IPYTHON_ZMQ: _detect_ipython_zmq,
IPYTHON: _detect_ipython,
AZURESYNAPSE: _detect_azure_synapse,
}

def detect(self):
Expand Down