{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "introduction" }, "source": [ "# Working with Tigris in Pixeltable\n", "\n", "This tutorial demonstrates how to configure Pixeltable to use [Tigris](https://tigrisdata.com) for storage. This lets you store unlimited amounts of images in Tigris' global data plane, allowing your images to load fast everywhere.\n", "\n", "## Prerequisites\n", "\n", "- A Tigris account, bucket, and access keypair ([https://storage.new](https://storage.new))\n", "\n", "## Important notes\n", "\n", "- Tigris usage may incur costs based on your plan.\n", "- Be mindful of sensitive data and consider security measures when integrating with external services.\n", "\n", "First you need to install required libraries and enter a Tigris access keypair obtained via the Tigris Admin Console." ] }, { "cell_type": "markdown", "metadata": { "id": "mPfFuWBgZJ5q" }, "source": [ "## Set up environment\n", "\n", "First, let's install Pixeltable:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "PrJK4OcmZJ5q", "outputId": "19dd3989-7837-403b-d8ec-d24bfcdb39ad" }, "outputs": [], "source": [ "%pip install -qU pixeltable datasets" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Configure authentication\n", "\n", "These steps will have you enter in your Tigris credentials:" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [], "source": [ "import os\n", "from getpass import getpass\n", "\n", "os.environ['AWS_ACCESS_KEY_ID'] = getpass('Tigris access key ID')\n", "os.environ['AWS_SECRET_ACCESS_KEY'] = getpass('Tigris secret access key')\n", "bucket_name = getpass('Tigris bucket name')\n", "\n", "os.environ['AWS_ENDPOINT_URL_S3'] = 'https://t3.storage.dev'\n", "os.environ['AWS_REGION'] = 'auto'\n", "os.environ['PIXELTABLE_INPUT_MEDIA_DEST'] = f's3://{bucket_name}/input/'\n", "os.environ['PIXELTABLE_OUTPUT_MEDIA_DEST'] = f's3://{bucket_name}/output/'" ] }, { "cell_type": "markdown", "metadata": { "id": "-hdc6e78ZJ5r" }, "source": [ "## Create a table for images\n", "\n", "Now let's create a table that will contain images from the [XeIaso/botw-screenshots-captioned](https://huggingface.co/datasets/XeIaso/botw-screenshots-captioned) dataset:" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Created directory 'tigris'.\n", "Created table 'screenshots'.\n", "Inserting rows into `screenshots`: 100 rows [00:01, 51.72 rows/s]\n", "Inserting rows into `screenshots`: 100 rows [00:01, 55.57 rows/s]\n", "Inserting rows into `screenshots`: 100 rows [00:01, 52.74 rows/s]\n", "Inserting rows into `screenshots`: 100 rows [00:02, 33.96 rows/s]\n", "Inserting rows into `screenshots`: 100 rows [00:02, 42.64 rows/s]\n", "Inserting rows into `screenshots`: 100 rows [00:02, 39.65 rows/s]\n", "Inserting rows into `screenshots`: 100 rows [00:02, 47.36 rows/s]\n", "Inserting rows into `screenshots`: 28 rows [00:00, 6786.12 rows/s]\n", "Inserted 728 rows with 0 errors.\n" ] } ], "source": [ "import pixeltable as pxt\n", "from datasets import load_dataset\n", "\n", "# Create directory for this demo\n", "pxt.drop_dir('tigris', force=True)\n", "pxt.create_dir('tigris', if_exists='replace')\n", "\n", "\n", "# Load the dataset\n", "ds = load_dataset('XeIaso/botw-screenshots-captioned')\n", "# Import it to pixeltable with the name screenshots\n", "pxt.drop_table('tigris/screenshots', force=True)\n", "screenshots = pxt.create_table(\n", " 'tigris/screenshots', source=ds, if_exists='replace'\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Once the import is done, you can create thumbnails with a [computed column](https://docs.pixeltable.com/tutorials/computed-columns):" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Added 728 column values with 0 errors.\n" ] }, { "data": { "text/plain": [ "728 rows updated, 728 values computed." ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Add a computed column for thumbnails\n", "# Uses output_media_dest by default, or specify a custom destination\n", "screenshots.add_computed_column(\n", " thumbnail=screenshots.image.resize((256, 256)),\n", " destination=f's3://{bucket_name}/botw-screenshots/thumbnails/',\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And then inspect that with the `collect` method:" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| image | \n", "label | \n", "text | \n", "thumbnail | \n", "
|---|---|---|---|
\n",
" | \n",
" F1C11A22FAEE3B82F21B330E1B786A39 | \n", "in_BOTW masterpiece, best quality, 8k, cinematic screenshot from The Legend of Zelda: Breath of the Wild, close-up of the Roc banner, detailed intricate design, golden accents, dynamic lighting, cinematic, fantastical, fantasy. | \n", "\n",
" | \n",
"