From 4eadcec19480434e2d245d8f6a592a2b8dbca289 Mon Sep 17 00:00:00 2001 From: Matteo Mortari Date: Wed, 11 Sep 2024 21:29:21 +0200 Subject: [PATCH] docs: add info about installing extras (#373) * docs: add info about installing extras Signed-off-by: Matteo Mortari * Update clients/python/README.md Co-authored-by: Isabella Basso Signed-off-by: Matteo Mortari * add error message details Co-authored-by: Isabella Basso Signed-off-by: Matteo Mortari --------- Signed-off-by: Matteo Mortari Co-authored-by: Isabella Basso --- clients/python/README.md | 32 +++++++++++++++++++- clients/python/src/model_registry/_client.py | 12 +++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/clients/python/README.md b/clients/python/README.md index 9e97e1ca..0c174fc0 100644 --- a/clients/python/README.md +++ b/clients/python/README.md @@ -2,9 +2,37 @@ [![Python](https://img.shields.io/badge/python%20-3.9%7C3.10%7C3.11%7C3.12-blue)](https://github.com/kubeflow/model-registry) [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](../../../LICENSE) +[![Read the Docs](https://img.shields.io/readthedocs/model-registry)](https://model-registry.readthedocs.io/en/latest/) +[![Tutorial Website](https://img.shields.io/badge/Website-green?style=plastic&label=Tutorial&labelColor=blue)](https://www.kubeflow.org/docs/components/model-registry/getting-started/) This library provides a high level interface for interacting with a model registry server. +## Installation + +In your Python environment, you can install the latest version of the Model Registry Python client with: + +``` +pip install --pre model-registry +``` + +### Installing extras + +Some capabilities of this Model Registry Python client, such as [importing model from Hugging Face](#importing-from-hugging-face-hub), +require additional dependencies. + +By [installing an extra variant](https://packaging.python.org/en/latest/tutorials/installing-packages/#installing-extras) of this package +the additional dependencies will be managed for you automatically, for instance with: + +``` +pip install --pre "model-registry[hf]" +``` + +This step is not required if you already installed the additional dependencies already, for instance with: + +``` +pip install huggingface-hub +``` + ## Basic usage ```py @@ -72,7 +100,9 @@ model = registry.register_model( ### Importing from Hugging Face Hub To import models from Hugging Face Hub, start by installing the `huggingface-hub` package, either directly or as an -extra (available as `model-registry[hf]`). +extra (available as `model-registry[hf]`). Reference section "[installing extras](#installing-extras)" above for +more information. + Models can be imported with ```py diff --git a/clients/python/src/model_registry/_client.py b/clients/python/src/model_registry/_client.py index b3aa0457..0cf2a7a7 100644 --- a/clients/python/src/model_registry/_client.py +++ b/clients/python/src/model_registry/_client.py @@ -247,7 +247,17 @@ def register_hf_model( try: from huggingface_hub import HfApi, hf_hub_url, utils except ImportError as e: - msg = "huggingface_hub is not installed" + msg = """package `huggingface-hub` is not installed. + To import models from Hugging Face Hub, start by installing the `huggingface-hub` package, either directly or as an + extra (available as `model-registry[hf]`), e.g.: + ```sh + !pip install --pre model-registry[hf] + ``` + or + ```sh + !pip install huggingface-hub + ``` + """ raise StoreError(msg) from e api = HfApi()