# Quickstart using CLI

## Prerequisites

Prior steps are logging in, creating a project and a dataset instance.&#x20;

More info about these steps is described at the [**Setup**](broken://pages/ERkSgwrMnaeqEZ15Wu04) page.

### Installing Leap CLI

Install `leapcli` using the following command:

```bash
pip install leapcli
```

Once installed successfully, the `leap` command shall be available.

### Leap Init

Once the `leap` CLI is installed, you can initialize your project to be synced with the Tensorleap platform.&#x20;

In the target project path, run the following command to initialize Tensorleap within the project:

```bash
leap init PROJECT_NAME DATASET_NAME
```

Replace the arguments with the corresponding value:

<table><thead><tr><th width="150">Args</th><th></th></tr></thead><tbody><tr><td><code>PROJECT_NAME</code></td><td>The name of the project</td></tr><tr><td><code>DATASET_NAME</code></td><td>The name of the <a href="/pages/aSFr9rK89lL6qA58cYVD#dataset-instance"><strong>Dataset Instance</strong></a></td></tr></tbody></table>

All the parameters are stored at the `.tensorleap/config.toml` file and could be changed if needed.

### Leap Login

In order to access the platform, we must run the `leap login` command within the initialized project path, as such:

```
leap login [API_ID] [API_KEY] [ORIGIN]
```

The `API_ID` , `API_KEY` and the `ORIGIN`, along with the full command, can easily be found by clicking the <img src="/files/XZK9nzEcOCPmY9kGPOJY" alt="" data-size="line"> button within the [**Resources Management**](/user-interface/resources-management.md) view.

### Dataset Integration

For Tensorleap to read the data and fetch it to the model for training or evaluation, we must provide a [**Dataset Script**](/tensorleap-integration/writing-integration-code.md#dataset-script). This script defines the **preprocessing** functio&#x6E;**, input/ground\_truth** encoders and **metadata** functions.&#x20;

The script should be set at the `.tensorleap/dataset.py` file.

{% hint style="info" %}
Important to note that this script should be contained and **not** use external project dependencies!
{% endhint %}

This script will later be synced with the [**Dataset Instance**](/tensorleap-integration/writing-integration-code.md#dataset-instance) set by the `DATASET_NAME` property above.

More info can be found at the Dataset Script page. A sample script can be found at the [MNIST Guide](/guides/full-guides/mnist-guide.md).

Additional examples can be found at the [**Tensorleap Examples**](https://github.com/tensorleap/tensorleap/) repository.

### Model Integration

&#x20;The model integration script is located at `.tensorleap/model.py`, an example script below:

{% tabs %}
{% tab title="Tensorflow" %}

```python
from pathlib import Path
from myproject.model import build_model # import from the parent project

def leap_save_model(target_file_path: Path):
    # Load your model
    model = build_model()
    # Save it to the path supplied as an arugment (has a .h5 suffix)
    model.save(target_file_path)
```

{% endtab %}

{% tab title="PyTorch" %}
Coming Soon
{% endtab %}
{% endtabs %}

The `leap_save_model` is automatically called by the CLI when pushing a model into the Tensorleap platform. Its purpose is to prepare and store the model in the provided `target_file_path`.

More info can be found at the Dataset Script page. A sample script can be found at the [MNIST Guide](/guides/full-guides/mnist-guide.md).

Additional examples can be found at the [**Tensorleap Examples**](https://github.com/tensorleap/tensorleap/) repository.

### Validation

You can validate the **dataset** and **model** scripts locally by using the following command:

```
leap check --all
```

This command will validate the scripts together with its synchronization with the Tensorleap platform.

### Synchronization

Once everything is validated, you can push the **dataset script** and **model** to the Tensorleap platform for further evaluation/training/analysis.

To push the **dataset script**, use the following command from the project path:

```bash
leap push --dataset
```

To push the model to the project, use the following command:

```bash
leap push --model
```

You can also set the `branch-name`, `description` and `model-name` as such:

```
leap push --model [--branch-name=<BRANCH_NAME> [--description=<DESCRIPTION>] 
          [--model-name=<MODEL_NAME>]
```

### What's Next?

You can now log in into the Tensorleap Platform within the UI, and find the imported model within the project, and the dataset within the [**Resources Management**](/user-interface/resources-management.md) view.

You can follow the next steps to prepare the model for analysis:

* Open up the current project (defined by the `PROJECT_NAME` above).\
  More info at [**Open a Project**](/user-interface/project.md#open-a-project)**.**
* Find the imported model on the Versions view, hover your cursor over the view and **click** <img src="/files/uG4lQceLsLKBgiqjLMTA" alt="" data-size="line"> on the right to **Open Commit**.
* Back on the **Network** view, set the [**Dataset** **Block**](/user-interface/project/network/network-mapping/create-a-mapping-deprecated/input-node.md#setup) to point to the `DATASET_NAME` [**Dataset Instance**](broken://pages/CBUAxbBBCSLCooJBRheA), and connect it to the first layer.
* Add the **ground truth**, **loss** and **optimizer** blocks, and connect them to the end of the network.\
  More info at [**Dataset Block Setup**](/user-interface/project/network/network-mapping/create-a-mapping-deprecated/input-node.md#setup) and [**Loss and Optimizer**](/user-interface/project/network/network-mapping/create-a-mapping-deprecated/loss-node.md)**.**
* Save the version model by clicking the <img src="/files/KufD8iWbuVi1Smd314P4" alt="" data-size="line"> button and set the `Revision Name` . This adds the new version to the [**Versions**](/user-interface/project/versions.md) view. More info at [**Save a Version**](/user-interface/project/versions.md#save-a-version).
* The model is ready for **training** or **evaluation**:&#x20;

  ***Already trained model*** - click <img src="/files/xQLJFeirGdnbihA8x9ac" alt="" data-size="line"> from the top bar to inference the data and collect metrics.\
  \&#xNAN;***Re-train / train from scratch in the Tensorleap platform*** - click <img src="/files/Yfz9C6ofZtY5K1NIve9n" alt="" data-size="line"> from the top bar to train the model.\
  More info at [Evaluate a Model](/user-interface/project/menu-bar/evaluate-a-model.md).
* After the process is done, the model is ready for analysis. More info at [Sample Analysis](/user-interface/dashboards/dashlets/sample-analysis.md).&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tensorleap.ai/getting-started/quickstart/quickstart-using-cli.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
