Skip to content

Commit

Permalink
docs: update image references with PIL
Browse files Browse the repository at this point in the history
  • Loading branch information
sdiazlor committed Sep 18, 2024
1 parent 59cc8ff commit d4188c5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
21 changes: 17 additions & 4 deletions argilla/docs/how_to_guides/record.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ Fields are the main pieces of information of the record. These are shown at firs

=== "Text"
Text fields expect input in the form of a `string`.

```python
record = rg.Record(
fields={"text": "Hello World, how are you?"}
Expand All @@ -167,14 +168,26 @@ Fields are the main pieces of information of the record. These are shown at firs

=== "Image"
Image fields expect a remote URL or local path to an image file in the form of a `string`, or a PIL object.

> Check the [Dataset.records - Python Reference](../reference/argilla/datasets/dataset_records.md) to see how to add records with with images in detail.

```python
record = rg.Record(
fields={"image": "https://example.com/image.jpg"}
)
records = [
rg.Record(
fields={"image": "https://example.com/image.jpg"}
),
rg.Record(
fields={"image": "path/to/image.jpg"}
),
rg.Record(
fields={"image": Image.open("path/to/image.jpg")}
),
]
```

=== "Chat"
Chat fields expects a list of dictionaries with the keys `role` and `content`, where the `role` identifies the interlocutor type (e.g., user, assistant, model, etc.), whereas the `content` contains the text of the message.
Chat fields expect a list of dictionaries with the keys `role` and `content`, where the `role` identifies the interlocutor type (e.g., user, assistant, model, etc.), whereas the `content` contains the text of the message.

```python
record = rg.Record(
fields={
Expand Down
23 changes: 20 additions & 3 deletions argilla/docs/reference/argilla/datasets/dataset_records.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,27 @@ Argilla datasets can contain image fields. You can add images to a dataset by pa
!!! note "As PIL objects"
To retrieve the images as rescaled PIL objects, you can use the `to_datasets` method when exporting the records, as shown in this [how-to guide](../../../how_to_guides/import_export.md).

=== "From a data structure with local file paths"

=== "From a data structure with remote URLs"

```python
data = [
{
"image": "https://example.com/image1.jpg",
},
{
"image": "https://example.com/image2.jpg",
},
]

dataset.records.log(data)
```

=== "From a data structure with local files or PIL objects"

```python
import os
from PIL import Image

image_dir = "path/to/images"

Expand All @@ -214,14 +230,15 @@ Argilla datasets can contain image fields. You can add images to a dataset by pa
"image": os.path.join(image_dir, "image1.jpg"), # (1)
},
{
"image": os.path.join(image_dir, "image2.jpg"),
"image": Image.open(os.path.join(image_dir, "image2.jpg")), # (2)
},
]

dataset.records.log(data)
```

1. The image can be referenced as either a remote URL, a local file path, or a PIL object.
1. The image is a local file path.
2. The image is a PIL object.

=== "From a Hugging Face dataset"

Expand Down
3 changes: 2 additions & 1 deletion argilla/docs/reference/argilla/settings/fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ data = rg.Dataset(
---


::: src.argilla.settings._field.TextField

::: src.argilla.settings._field.ImageField

::: src.argilla.settings._field.ChatField

0 comments on commit d4188c5

Please sign in to comment.