Skip to content

Commit

Permalink
Merge pull request #1676 from gchq/feature/BAI-1545-remove-team-and-t…
Browse files Browse the repository at this point in the history
…eams-endpoints-from-python-bailo-client

Remove team & teams endpoints from python bailo client
  • Loading branch information
PE39806 authored Dec 11, 2024
2 parents 3ebcd8a + b38b663 commit ec9591b
Show file tree
Hide file tree
Showing 17 changed files with 278 additions and 500 deletions.
103 changes: 22 additions & 81 deletions backend/docs/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Bailo Python Client
# Bailo Python Client Documentation

A simple Python API Wrapper for Bailo
The documentation for [a simple Python API Wrapper for Bailo](../../lib/python/README.md)

<br />

Expand All @@ -9,102 +9,43 @@ A simple Python API Wrapper for Bailo
<summary>Table of Contents</summary>
<ol>
<li>
<a href="#key-features">Key Features</a>
</li>
<li>
<a href="#installing">Installing</a>
</li>
<li>
<a href="#getting-started">Getting Started</a>
</li>
<li>
<a href="#development">Development</a>
<a href="#documentation">Documentation</a>
<ul>
<li><a href="#install-and-add-precommit">Precommits</a></li>
<li><a href="#testing">Testing</a></li>
<li>
<a href="#building-locally">Building locally</a>
<ul>
<li><a href="#prerequisites">Prerequisites</a></li>
<li><a href="#building">Building</a></li>
</ul>
</li>
</ul>
</li>
</ol>
</details>

<br />

## Key Features

- Uploading and downloading model binaries

## Installing

**Python 3.8.1 or higher is required**

```bash
pip install bailo
```

## Getting Started

```python
from bailo import Client, Model
client = Client("http://localhost:8080")

# Create a model
yolo = Model.create(
client=client,
name="YoloV4",
description="You only look once!",
team_id="Uncategorised"
)

yolo.card_from_schema("minimal-general-v10-beta")

# Create a new release
my_release = yolo.create_release(version="0.1.0",
notes="Beta")

# Upload a file to the release
with open("yolo.onnx") as f:
my_release.upload("yolo", f)
```

## Documentation

Documenation is rendered with Sphinx and served [here](https://gchq.github.io/Bailo/docs/python/index.html).
Documentation is rendered with Sphinx and served [here](https://gchq.github.io/Bailo/docs/python/index.html).

### Building locally

From the docs directory run either `make html` or `make.bat` on Windows. This will build it in the backend directory by
default.

## Development

### Install and add precommit

If already working on Bailo you may be prompted to overwrite Husky. Follow the instructions given by Git CLI.

```bash
pip install pre-commit
pre-commit install
```

### Install the package locally

```bash
pip install -e .
```

### Testing
<!-- prettier-ignore-start -->
> [!IMPORTANT]
> Python 3.8.1 or higher is required
<!-- prettier-ignore-end -->
The package uses Pytest to test packages. Tests can be ran accordingly from within this directory. Tests are split into
categories sections for automation purposes.
#### Prerequisites

In order to run integration tests make sure Bailo is running on `https://localhost:8080`:
From within the `backend/docs` directory:

```bash
pytest -m integration
pip install bailo -r requirements.txt
apt install -y pandoc
```

Run all other tests:
#### Building

```bash
pytest
```
From the docs directory run either `make html` (Linux & Mac) or `make.bat` (Windows). This will build it in the backend
directory by default.
6 changes: 3 additions & 3 deletions backend/docs/notebooks/access_requests_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"In this section, we'll create a new access request using the `AccessRequest.create()` classmethod. On the Bailo service, an access request must consist of at least 3 parameters upon creation. These are **model_id**, **schema_id** and **metadata**. Below, we use the `Client()` object created before when instantiating the new `AccessRequest()` object. We'll also need to create a new model on the service, which our access request will be for."
"In this section, we will create a new access request using the `AccessRequest.create()` classmethod. On the Bailo service, an access request must consist of at least 3 parameters upon creation. These are **model_id**, **schema_id** and **metadata**. Below, we use the `Client()` object created before when instantiating the new `AccessRequest()` object. We will also need to create a new model on the service, which our access request will be for."
]
},
{
Expand All @@ -87,7 +87,7 @@
"metadata": {},
"outputs": [],
"source": [
"model = Model.create(client=client, name=\"YOLOv5\", description=\"YOLOv5 model for object detection.\", team_id=\"uncategorised\")\n",
"model = Model.create(client=client, name=\"YOLOv5\", description=\"YOLOv5 model for object detection.\")\n",
"model_id = model.model_id\n",
"\n",
"metadata = {\"overview\": {\"entities\": [\"user\"], \"name\": \"test\", \"endDate\": \"1970-01-01\"}}\n",
Expand Down Expand Up @@ -117,7 +117,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"In this section, we'll retrieve our previous access request using the `AccessRequest.from_id()` classmethod. This will create your `AccessRequest()` object as before, but using existing information retrieved from the service."
"In this section, we will retrieve our previous access request using the `AccessRequest.from_id()` classmethod. This will create your `AccessRequest()` object as before, but using existing information retrieved from the service."
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions backend/docs/notebooks/datacards_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"\n",
"### Creating and updating the base datacard\n",
"\n",
"In this section, we'll create a new datacard using the `Datacard.create()` classmethod. On the Bailo service, a datacard must consist of at least 4 parameters upon creation. These are **name**, **description**, **visibility** and **team_id**. Below, we use the `Client()` object created before when instantiating the new `Datacard()` object. \n",
"In this section, we will create a new datacard using the `Datacard.create()` classmethod. On the Bailo service, a datacard must consist of at least 4 parameters upon creation. These are **name**, **description** and **visibility**. Below, we use the `Client()` object created before when instantiating the new `Datacard()` object. \n",
"\n",
"NOTE: This creates the datacard on your Bailo service too! The `datacard_id` is assigned by the backend, and we will use this later to retrieve the datacard. *Like with models on Bailo, the actual datacard has not been populated at this stage.*"
]
Expand All @@ -85,7 +85,7 @@
"metadata": {},
"outputs": [],
"source": [
"datacard = Datacard.create(client=client, name=\"ImageNet\", description=\"ImageNet dataset consisting of images.\", team_id=\"uncategorised\")\n",
"datacard = Datacard.create(client=client, name=\"ImageNet\", description=\"ImageNet dataset consisting of images.\")\n",
"\n",
"datacard_id = datacard.datacard_id"
]
Expand Down Expand Up @@ -131,7 +131,7 @@
"source": [
"If successful, the above will have created a new datacard, and the `data_card_version` attribute should be set to 1.\n",
"\n",
"Next, we can populate the data using the `update_data_card()` method. This can be used any time you want to make changes, and the backend will create a new datacard version each time. We'll learn how to retrieve datacards later (either the latest, or a specific release).\n",
"Next, we can populate the data using the `update_data_card()` method. This can be used any time you want to make changes, and the backend will create a new datacard version each time. We will learn how to retrieve datacards later (either the latest, or a specific release).\n",
"\n",
"NOTE: Your datacard must match the schema, otherwise an error will be thrown."
]
Expand Down Expand Up @@ -170,7 +170,7 @@
"\n",
"### Using the .from_id() method\n",
"\n",
"In this section, we'll retrieve our previous datacard using the `Datacard.from_id()` classmethod. This will create your `Datacard()` object as before, but using existing information retrieved from the service."
"In this section, we will retrieve our previous datacard using the `Datacard.from_id()` classmethod. This will create your `Datacard()` object as before, but using existing information retrieved from the service."
]
},
{
Expand Down
10 changes: 5 additions & 5 deletions backend/docs/notebooks/experiment_tracking_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"\n",
"### Connecting with Bailo\n",
"\n",
"In order to create an `Experiment()` object, you'll first need to have a Bailo `Model()` object, and thus a defined `Client()` too. We learned how to do this in a previous notebook, but this time we'll create a new model with a custom schema which supports model metrics. *More on that later...*"
"In order to create an `Experiment()` object, you'll first need to have a Bailo `Model()` object, and thus a defined `Client()` too. We learned how to do this in a previous notebook, but this time we will create a new model with a custom schema which supports model metrics. *More on that later...*"
]
},
{
Expand Down Expand Up @@ -69,7 +69,7 @@
"\n",
"# Creating a demo model\n",
"\n",
"model = Model.create(client=client, name=\"YOLOv5\", description=\"YOLOv5 model for object detection.\", team_id=\"uncategorised\")"
"model = Model.create(client=client, name=\"YOLOv5\", description=\"YOLOv5 model for object detection.\")"
]
},
{
Expand All @@ -79,7 +79,7 @@
"source": [
"### Setting up MLFlow Tracking\n",
"\n",
"In order to complete the integration element of this tutorial, we'll need to set up a local instance of MLFlow Tracking, and create a sample experiment run. *This will not contain any actual model training and is only to demonstrate the functionality of Bailo.*\n",
"In order to complete the integration element of this tutorial, we will need to set up a local instance of MLFlow Tracking, and create a sample experiment run. *This will not contain any actual model training and is only to demonstrate the functionality of Bailo.*\n",
"\n",
"Run `mlflow ui` on the command line. Typically this will run on **localhost:5000** and the UI can be accessed on a browser"
]
Expand Down Expand Up @@ -156,7 +156,7 @@
"\n",
"You can run experiments directly using the Bailo python client as follows.\n",
"\n",
"**NOTE**: This will only work for sequential experiment runs, so if you're running experiments in parallel then it would be better to use **MLFlow Tracking**. We'll learn how to import completed experiments from MLFlow in the next section."
"**NOTE**: This will only work for sequential experiment runs, so if you're running experiments in parallel then it would be better to use **MLFlow Tracking**. We will learn how to import completed experiments from MLFlow in the next section."
]
},
{
Expand Down Expand Up @@ -218,7 +218,7 @@
"source": [
"## Importing existing experiments from MLFlow into Bailo\n",
"\n",
"As previously mentioned, you can import existing experiments into the `Experiment()` class by using the `Experiment.from_mlflow()` method. You must provide the **MLFlow tracking URI** and the experiment ID. To get the experiement ID, go to the link provided in the cell \"Creating a dummy MLFlow experiment run\". In the details section you will see \"Experiment ID\", copy this ID and add it to the argument **experiment_id**. ![image.png](img/experiment_id.png)"
"You can import existing experiments into the `Experiment()` class by using the `Experiment.from_mlflow()` method. You must provide the **MLFlow tracking URI** and the experiment ID. To get the experiment ID, go to the link provided in the cell \"Creating a dummy MLFlow experiment run\". In the details section you will see \"Experiment ID\", copy this ID and add it to the argument **experiment_id**. ![image.png](img/experiment_id.png)"
]
},
{
Expand Down
18 changes: 9 additions & 9 deletions backend/docs/notebooks/models_and_releases_demo_pytorch.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"\n",
"### Creating and updating the base model\n",
"\n",
"In this section, we'll create a new model representing ResNet-50 using the `Model.create()` classmethod. On the Bailo service, a model must consist of at least 4 parameters upon creation. These are **name**, **description**, **visibility** and **team_id**. Other attributes like model cards, files, or releases are added later on. Below, we use the `Client()` object created before when instantiating the new `Model()` object. \n",
"In this section, we will create a new model representing ResNet-50 using the `Model.create()` classmethod. On the Bailo service, a model must consist of at least 4 parameters upon creation. These are **name**, **description** and **visibility**. Other attributes like model cards, files, or releases are added later on. Below, we use the `Client()` object created before when instantiating the new `Model()` object. \n",
"\n",
"NOTE: This creates the model on your Bailo service too! The `model_id` is assigned by the backend, and we will use this later to retrieve the model."
]
Expand All @@ -102,7 +102,7 @@
"metadata": {},
"outputs": [],
"source": [
"model = Model.create(client=client, name=\"ResNet-50\", description=\"ResNet-50 model for image classification.\", team_id=\"uncategorised\")\n",
"model = Model.create(client=client, name=\"ResNet-50\", description=\"ResNet-50 model for image classification.\")\n",
"\n",
"model_id = model.model_id"
]
Expand Down Expand Up @@ -151,7 +151,7 @@
"\n",
"### Creating and populated a new model card with a template\n",
"\n",
"When creating a model card from a template, we need to use a preexisting model card as our template. First we create a new model, to create the new model card we use the `card_from_template` method and pass our chosen template model's ID. \n",
"When creating a model card from a template, we need to use a pre-existing model card as our template. First we create a new model, to create the new model card we use the `card_from_template` method and pass our chosen template model's ID. \n",
"\n",
"\n"
]
Expand All @@ -163,7 +163,7 @@
"outputs": [],
"source": [
"model2 = Model.create(\n",
" client=client, name=\"ResNet-50\", description=\"ResNet-50 model for image classification.\", team_id=\"uncategorised\"\n",
" client=client, name=\"ResNet-50\", description=\"ResNet-50 model for image classification.\"\n",
")\n",
"\n",
"model2_id = model2.model_id\n",
Expand All @@ -180,7 +180,7 @@
"source": [
"If successful, the above will have created a new model card, and the `model_card_version` attribute should be set to 1.\n",
"\n",
"Next, we can populate the model card using the `update_model_card()` method. This can be used any time you want to make changes, and the backend will create a new model card version each time. We'll learn how to retrieve model cards later (either the latest, or a specific release).\n",
"Next, we can populate the model card using the `update_model_card()` method. This can be used any time you want to make changes, and the backend will create a new model card version each time. We will learn how to retrieve model cards later (either the latest, or a specific release).\n",
"\n",
"NOTE: Your model card must match the schema, otherwise an error will be thrown."
]
Expand Down Expand Up @@ -220,7 +220,7 @@
"\n",
"### Using the .from_id() method\n",
"\n",
"In this section, we'll retrieve our previous model using the `Model.from_id()` classmethod. This will create your `Model()` object as before, but using existing information retrieved from the service."
"In this section, we will retrieve our previous model using the `Model.from_id()` classmethod. This will create your `Model()` object as before, but using existing information retrieved from the service."
]
},
{
Expand Down Expand Up @@ -337,7 +337,7 @@
"source": [
"### Downloading weights from the release\n",
"\n",
"Similarly you can also download specific files from release using the `download()` method. In this case, we'll write them to a new file: **bailo_resnet50_weights.pth**. **NOTE**: `filename` refers to the filename on Bailo, and `path` is the local destination for your download.\n",
"You can also download specific files from release using the `download()` method. In this case, we will write them to a new file: **bailo_resnet50_weights.pth**. **NOTE**: `filename` refers to the filename on Bailo, and `path` is the local destination for your download.\n",
"\n",
"In addition to this, you can also use the `download_all()` method by providing a local directory path as `path`. By default, this will download all files, but you can provide `include` and `exclude` lists, e.g. `include=[\"*.txt\", \"*.json\"]` to only include TXT or JSON files. "
]
Expand Down Expand Up @@ -378,7 +378,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"If the message \"**All keys matched successfully**\" is displayed, we have successfully initated our model."
"If the message \"**All keys matched successfully**\" is displayed, we have successfully initiated our model."
]
},
{
Expand All @@ -400,7 +400,7 @@
"* Libraries used for the model (e.g. PyTorch).\n",
"* Model card search (string to be found in model cards).\n",
"\n",
"In the below example, we'll just search for all models with no filters."
"In the below example, we will just search for all models with no filters."
]
},
{
Expand Down
Loading

0 comments on commit ec9591b

Please sign in to comment.