{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "O7wvDb5Xq0ZH" }, "source": [ "# Vision Agents with smolagents\n", "\n", "\n", "This notebook is part of the [Hugging Face Agents Course](https://www.hf.co/learn/agents-course), a free Course from beginner to expert, where you learn to build Agents.\n", "\n", "![Agents course share](https://huggingface.co./datasets/agents-course/course-images/resolve/main/en/communication/share.png)" ] }, { "cell_type": "markdown", "metadata": { "id": "fqKoOdz8q6fF" }, "source": [ "## Let's install the dependencies and login to our HF account to access the Inference API\n", "\n", "If you haven't installed `smolagents` yet, you can do so by running the following command:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "m_muGXjDRhTD" }, "outputs": [], "source": [ "!pip install smolagents" ] }, { "cell_type": "markdown", "source": [ "Let's also login to the Hugging Face Hub to have access to the Inference API." ], "metadata": { "id": "WJGFjRbZbL50" } }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "MnLNhxDzRiKh" }, "outputs": [], "source": [ "from huggingface_hub import notebook_login\n", "\n", "notebook_login()" ] }, { "cell_type": "markdown", "metadata": { "id": "qOp72sO9q-TD" }, "source": [ "## Providing Images at the Start of the Agent's Execution\n", "\n", "In this approach, images are passed to the agent at the start and stored as `task_images` alongside the task prompt. The agent then processes these images throughout its execution. \n", "\n", "Consider the case where Alfred wants to verify the identities of the superheroes attending the party. He already has a dataset of images from previous parties with the names of the guests. Given a new visitor's image, the agent can compare it with the existing dataset and make a decision about letting them in. \n", "\n", "In this case, a guest is trying to enter, and Alfred suspects that this visitor might be The Joker impersonating Wonder Woman. Alfred needs to verify their identity to prevent anyone unwanted from entering. \n", "\n", "Let’s build the example. First, the images are loaded. In this case, we use images from Wikipedia to keep the example minimal, but image the possible use-case!" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "BI9E3okPR5wc" }, "outputs": [], "source": [ "from PIL import Image\n", "import requests\n", "from io import BytesIO\n", "\n", "image_urls = [\n", " \"https://upload.wikimedia.org/wikipedia/commons/e/e8/The_Joker_at_Wax_Museum_Plus.jpg\",\n", " \"https://upload.wikimedia.org/wikipedia/en/9/98/Joker_%28DC_Comics_character%29.jpg\"\n", "]\n", "\n", "images = []\n", "for url in image_urls:\n", " response = requests.get(url)\n", " image = Image.open(BytesIO(response.content)).convert(\"RGB\")\n", " images.append(image)" ] }, { "cell_type": "markdown", "source": [ "Now that we have the images, the agent will tell us wether the guests is actually a superhero (Wonder Woman) or a villian (The Joker)." ], "metadata": { "id": "vUBQjETkbRU6" } }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "6HroQ3eIT-3m" }, "outputs": [], "source": [ "from google.colab import userdata\n", "import os\n", "os.environ[\"OPENAI_API_KEY\"] = userdata.get('OPENAI_API_KEY')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 1000 }, "id": "A8qra0deRkUY", "outputId": "2867daa1-e84e-4d02-ef10-eeeaf3ea863d" }, "outputs": [ { "data": { "text/html": [ "
╭──────────────────────────────────────────────────── New run ────────────────────────────────────────────────────╮\n",
              "                                                                                                                 \n",
              " Describe the costume and makeup that the comic character in these photos is wearing and return the description. \n",
              "     Tell me if the guest is The Joker or Wonder Woman.                                                          \n",
              "                                                                                                                 \n",
              "╰─ OpenAIServerModel - gpt-4o ────────────────────────────────────────────────────────────────────────────────────╯\n",
              "
\n" ], "text/plain": [ "\u001b[38;2;212;183;2m╭─\u001b[0m\u001b[38;2;212;183;2m───────────────────────────────────────────────────\u001b[0m\u001b[38;2;212;183;2m \u001b[0m\u001b[1;38;2;212;183;2mNew run\u001b[0m\u001b[38;2;212;183;2m \u001b[0m\u001b[38;2;212;183;2m───────────────────────────────────────────────────\u001b[0m\u001b[38;2;212;183;2m─╮\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[1mDescribe the costume and makeup that the comic character in these photos is wearing and return the description.\u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[1m Tell me if the guest is The Joker or Wonder Woman.\u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m│\u001b[0m \u001b[38;2;212;183;2m│\u001b[0m\n", "\u001b[38;2;212;183;2m╰─\u001b[0m\u001b[38;2;212;183;2m OpenAIServerModel - gpt-4o \u001b[0m\u001b[38;2;212;183;2m───────────────────────────────────────────────────────────────────────────────────\u001b[0m\u001b[38;2;212;183;2m─╯\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Step 1 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n",
              "
\n" ], "text/plain": [ "\u001b[38;2;212;183;2m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ \u001b[0m\u001b[1mStep \u001b[0m\u001b[1;36m1\u001b[0m\u001b[38;2;212;183;2m ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Output message of the LLM: ────────────────────────────────────────────────────────────────────────────────────────\n",
              "I don't have the capability to identify or recognize people in images, but I can describe what I see.              \n",
              "                                                                                                                   \n",
              "The character in the photos you provided is wearing:                                                               \n",
              "                                                                                                                   \n",
              "1. **Costume:**                                                                                                    \n",
              "   - A purple suit with a large bow tie in one image.                                                              \n",
              "   - A white flower lapel and card in another image.                                                               \n",
              "   - The style is flamboyant and colorful, typical of a comic villain.                                             \n",
              "                                                                                                                   \n",
              "2. **Makeup:**                                                                                                     \n",
              "   - White face makeup covering the entire face.                                                                   \n",
              "   - Red lips forming a wide, exaggerated smile.                                                                   \n",
              "   - Dark makeup around the eyes.                                                                                  \n",
              "   - Green hair.                                                                                                   \n",
              "                                                                                                                   \n",
              "From the description, this character resembles The Joker, a well-known comic book villain.                         \n",
              "
\n" ], "text/plain": [ "\u001b[1;3mOutput message of the LLM:\u001b[0m \u001b[38;2;212;183;2m────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\n", "\u001b[38;2;230;237;243;48;2;13;17;23mI\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mdon't\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mhave\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mthe\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mcapability\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mto\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23midentify\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mor\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mrecognize\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mpeople\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23min\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mimages,\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mbut\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mI\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mcan\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mdescribe\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mwhat\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mI\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23msee.\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[38;2;230;237;243;48;2;13;17;23mThe\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mcharacter\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23min\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mthe\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mphotos\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23myou\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mprovided\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mis\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mwearing:\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[38;2;255;123;114;48;2;13;17;23m1.\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[1;38;2;230;237;243;48;2;13;17;23m**Costume:**\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[38;2;110;118;129;48;2;13;17;23m \u001b[0m\u001b[38;2;255;123;114;48;2;13;17;23m-\u001b[0m\u001b[38;2;110;118;129;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mA\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mpurple\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23msuit\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mwith\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23ma\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mlarge\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mbow\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mtie\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23min\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mone\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mimage.\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[38;2;110;118;129;48;2;13;17;23m \u001b[0m\u001b[38;2;255;123;114;48;2;13;17;23m-\u001b[0m\u001b[38;2;110;118;129;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mA\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mwhite\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mflower\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mlapel\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mand\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mcard\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23min\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23manother\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mimage.\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[38;2;110;118;129;48;2;13;17;23m \u001b[0m\u001b[38;2;255;123;114;48;2;13;17;23m-\u001b[0m\u001b[38;2;110;118;129;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mThe\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mstyle\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mis\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mflamboyant\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mand\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mcolorful,\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mtypical\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mof\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23ma\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mcomic\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mvillain.\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[38;2;255;123;114;48;2;13;17;23m2.\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[1;38;2;230;237;243;48;2;13;17;23m**Makeup:**\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[38;2;110;118;129;48;2;13;17;23m \u001b[0m\u001b[38;2;255;123;114;48;2;13;17;23m-\u001b[0m\u001b[38;2;110;118;129;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mWhite\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mface\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mmakeup\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mcovering\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mthe\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mentire\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mface.\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[38;2;110;118;129;48;2;13;17;23m \u001b[0m\u001b[38;2;255;123;114;48;2;13;17;23m-\u001b[0m\u001b[38;2;110;118;129;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mRed\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mlips\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mforming\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23ma\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mwide,\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mexaggerated\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23msmile.\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[38;2;110;118;129;48;2;13;17;23m \u001b[0m\u001b[38;2;255;123;114;48;2;13;17;23m-\u001b[0m\u001b[38;2;110;118;129;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mDark\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mmakeup\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23maround\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mthe\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23meyes.\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[38;2;110;118;129;48;2;13;17;23m \u001b[0m\u001b[38;2;255;123;114;48;2;13;17;23m-\u001b[0m\u001b[38;2;110;118;129;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mGreen\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mhair.\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[38;2;230;237;243;48;2;13;17;23mFrom\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mthe\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mdescription,\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mthis\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mcharacter\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mresembles\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mThe\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mJoker,\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23ma\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mwell-known\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mcomic\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mbook\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mvillain.\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Error in code parsing:\n",
              "Your code snippet is invalid, because the regex pattern ```(?:py|python)?\\n(.*?)\\n``` was not found in it.\n",
              "Here is your code snippet:\n",
              "I don't have the capability to identify or recognize people in images, but I can describe what I see.\n",
              "\n",
              "The character in the photos you provided is wearing:\n",
              "\n",
              "1. **Costume:**\n",
              "   - A purple suit with a large bow tie in one image.\n",
              "   - A white flower lapel and card in another image.\n",
              "   - The style is flamboyant and colorful, typical of a comic villain.\n",
              "\n",
              "2. **Makeup:**\n",
              "   - White face makeup covering the entire face.\n",
              "   - Red lips forming a wide, exaggerated smile.\n",
              "   - Dark makeup around the eyes.\n",
              "   - Green hair.\n",
              "\n",
              "From the description, this character resembles The Joker, a well-known comic book villain.\n",
              "Make sure to include code with the correct pattern, for instance:\n",
              "Thoughts: Your thoughts\n",
              "Code:\n",
              "```py\n",
              "# Your python code here\n",
              "```<end_code>\n",
              "Make sure to provide correct code blobs.\n",
              "
\n" ], "text/plain": [ "\u001b[1;31mError in code parsing:\u001b[0m\n", "\u001b[1;31mYour code snippet is invalid, because the regex pattern ```\u001b[0m\u001b[1;31m(\u001b[0m\u001b[1;31m?:py|python\u001b[0m\u001b[1;31m)\u001b[0m\u001b[1;31m?\\\u001b[0m\u001b[1;31mn\u001b[0m\u001b[1;31m(\u001b[0m\u001b[1;31m.*?\u001b[0m\u001b[1;31m)\u001b[0m\u001b[1;31m\\n``` was not found in it.\u001b[0m\n", "\u001b[1;31mHere is your code snippet:\u001b[0m\n", "\u001b[1;31mI don't have the capability to identify or recognize people in images, but I can describe what I see.\u001b[0m\n", "\n", "\u001b[1;31mThe character in the photos you provided is wearing:\u001b[0m\n", "\n", "\u001b[1;31m1\u001b[0m\u001b[1;31m. **Costume:**\u001b[0m\n", "\u001b[1;31m - A purple suit with a large bow tie in one image.\u001b[0m\n", "\u001b[1;31m - A white flower lapel and card in another image.\u001b[0m\n", "\u001b[1;31m - The style is flamboyant and colorful, typical of a comic villain.\u001b[0m\n", "\n", "\u001b[1;31m2\u001b[0m\u001b[1;31m. **Makeup:**\u001b[0m\n", "\u001b[1;31m - White face makeup covering the entire face.\u001b[0m\n", "\u001b[1;31m - Red lips forming a wide, exaggerated smile.\u001b[0m\n", "\u001b[1;31m - Dark makeup around the eyes.\u001b[0m\n", "\u001b[1;31m - Green hair.\u001b[0m\n", "\n", "\u001b[1;31mFrom the description, this character resembles The Joker, a well-known comic book villain.\u001b[0m\n", "\u001b[1;31mMake sure to include code with the correct pattern, for instance:\u001b[0m\n", "\u001b[1;31mThoughts: Your thoughts\u001b[0m\n", "\u001b[1;31mCode:\u001b[0m\n", "\u001b[1;31m```py\u001b[0m\n", "\u001b[1;31m# Your python code here\u001b[0m\n", "\u001b[1;31m```\u001b[0m\u001b[1;31m<\u001b[0m\u001b[1;31mend_code\u001b[0m\u001b[1;31m>\u001b[0m\n", "\u001b[1;31mMake sure to provide correct code blobs.\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
[Step 0: Duration 4.30 seconds| Input tokens: 3,004 | Output tokens: 139]\n",
              "
\n" ], "text/plain": [ "\u001b[2m[Step 0: Duration 4.30 seconds| Input tokens: 3,004 | Output tokens: 139]\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Step 2 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n",
              "
\n" ], "text/plain": [ "\u001b[38;2;212;183;2m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ \u001b[0m\u001b[1mStep \u001b[0m\u001b[1;36m2\u001b[0m\u001b[38;2;212;183;2m ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Output message of the LLM: ────────────────────────────────────────────────────────────────────────────────────────\n",
              "I'm unable to identify characters in images, but I can offer a description.                                        \n",
              "                                                                                                                   \n",
              "Thought: From the images, I will describe the costume and makeup.                                                  \n",
              "                                                                                                                   \n",
              "Code:                                                                                                              \n",
              "```py                                                                                                              \n",
              "description = \"\"\"                                                                                                  \n",
              "1. Costume:                                                                                                        \n",
              "   - A purple suit with a yellow shirt and a large purple bow tie.                                                 \n",
              "   - Features a white flower lapel and a playing card in the second image.                                         \n",
              "   - The style is flamboyant, consistent with a comic villain.                                                     \n",
              "                                                                                                                   \n",
              "2. Makeup:                                                                                                         \n",
              "   - White face makeup covering the entire face.                                                                   \n",
              "   - Red lips forming a wide, exaggerated smile.                                                                   \n",
              "   - Blue eyeshadow with dark eye accents.                                                                         \n",
              "   - Slicked-back green hair.                                                                                      \n",
              "\"\"\"                                                                                                                \n",
              "                                                                                                                   \n",
              "# Based on the description, this character resembles The Joker.                                                    \n",
              "character = \"The Joker\"                                                                                            \n",
              "                                                                                                                   \n",
              "final_answer({\"description\": description, \"character\": character})                                                 \n",
              "```                                                                                                                \n",
              "
\n" ], "text/plain": [ "\u001b[1;3mOutput message of the LLM:\u001b[0m \u001b[38;2;212;183;2m────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\n", "\u001b[38;2;230;237;243;48;2;13;17;23mI'm\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23munable\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mto\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23midentify\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mcharacters\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23min\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mimages,\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mbut\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mI\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mcan\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23moffer\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23ma\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mdescription.\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[38;2;230;237;243;48;2;13;17;23mThought:\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mFrom\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mthe\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mimages,\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mI\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mwill\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mdescribe\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mthe\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mcostume\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mand\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mmakeup.\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[38;2;230;237;243;48;2;13;17;23mCode:\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[38;2;165;214;255;48;2;13;17;23m```\u001b[0m\u001b[38;2;165;214;255;48;2;13;17;23mpy\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[38;2;230;237;243;48;2;13;17;23mdescription\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[1;38;2;255;123;114;48;2;13;17;23m=\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;165;214;255;48;2;13;17;23m\"\"\"\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[38;2;165;214;255;48;2;13;17;23m1. Costume:\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[38;2;165;214;255;48;2;13;17;23m - A purple suit with a yellow shirt and a large purple bow tie.\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[38;2;165;214;255;48;2;13;17;23m - Features a white flower lapel and a playing card in the second image.\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[38;2;165;214;255;48;2;13;17;23m - The style is flamboyant, consistent with a comic villain.\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[38;2;165;214;255;48;2;13;17;23m2. Makeup:\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[38;2;165;214;255;48;2;13;17;23m - White face makeup covering the entire face.\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[38;2;165;214;255;48;2;13;17;23m - Red lips forming a wide, exaggerated smile.\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[38;2;165;214;255;48;2;13;17;23m - Blue eyeshadow with dark eye accents.\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[38;2;165;214;255;48;2;13;17;23m - Slicked-back green hair.\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[38;2;165;214;255;48;2;13;17;23m\"\"\"\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[3;38;2;139;148;158;48;2;13;17;23m# Based on the description, this character resembles The Joker.\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[38;2;230;237;243;48;2;13;17;23mcharacter\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[1;38;2;255;123;114;48;2;13;17;23m=\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;165;214;255;48;2;13;17;23m\"\u001b[0m\u001b[38;2;165;214;255;48;2;13;17;23mThe Joker\u001b[0m\u001b[38;2;165;214;255;48;2;13;17;23m\"\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[38;2;230;237;243;48;2;13;17;23mfinal_answer\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m(\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m{\u001b[0m\u001b[38;2;165;214;255;48;2;13;17;23m\"\u001b[0m\u001b[38;2;165;214;255;48;2;13;17;23mdescription\u001b[0m\u001b[38;2;165;214;255;48;2;13;17;23m\"\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m:\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mdescription\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m,\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;165;214;255;48;2;13;17;23m\"\u001b[0m\u001b[38;2;165;214;255;48;2;13;17;23mcharacter\u001b[0m\u001b[38;2;165;214;255;48;2;13;17;23m\"\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m:\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m \u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23mcharacter\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m}\u001b[0m\u001b[38;2;230;237;243;48;2;13;17;23m)\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n", "\u001b[38;2;165;214;255;48;2;13;17;23m```\u001b[0m\u001b[48;2;13;17;23m \u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Executing parsed code: ──────────────────────────────────────────────────────────────────────────────────────── \n",
              "  description = \"\"\"                                                                                                \n",
              "  1. Costume:                                                                                                      \n",
              "     - A purple suit with a yellow shirt and a large purple bow tie.                                               \n",
              "     - Features a white flower lapel and a playing card in the second image.                                       \n",
              "     - The style is flamboyant, consistent with a comic villain.                                                   \n",
              "                                                                                                                   \n",
              "  2. Makeup:                                                                                                       \n",
              "     - White face makeup covering the entire face.                                                                 \n",
              "     - Red lips forming a wide, exaggerated smile.                                                                 \n",
              "     - Blue eyeshadow with dark eye accents.                                                                       \n",
              "     - Slicked-back green hair.                                                                                    \n",
              "  \"\"\"                                                                                                              \n",
              "                                                                                                                   \n",
              "  # Based on the description, this character resembles The Joker.                                                  \n",
              "  character = \"The Joker\"                                                                                          \n",
              "                                                                                                                   \n",
              "  final_answer({\"description\": description, \"character\": character})                                               \n",
              " ───────────────────────────────────────────────────────────────────────────────────────────────────────────────── \n",
              "
\n" ], "text/plain": [ " ─ \u001b[1mExecuting parsed code:\u001b[0m ──────────────────────────────────────────────────────────────────────────────────────── \n", " \u001b[38;2;248;248;242;48;2;39;40;34mdescription\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;255;70;137;48;2;39;40;34m=\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\"\"\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[38;2;230;219;116;48;2;39;40;34m1. Costume:\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[38;2;230;219;116;48;2;39;40;34m - A purple suit with a yellow shirt and a large purple bow tie.\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[38;2;230;219;116;48;2;39;40;34m - Features a white flower lapel and a playing card in the second image.\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[38;2;230;219;116;48;2;39;40;34m - The style is flamboyant, consistent with a comic villain.\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[38;2;230;219;116;48;2;39;40;34m2. Makeup:\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[38;2;230;219;116;48;2;39;40;34m - White face makeup covering the entire face.\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[38;2;230;219;116;48;2;39;40;34m - Red lips forming a wide, exaggerated smile.\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[38;2;230;219;116;48;2;39;40;34m - Blue eyeshadow with dark eye accents.\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[38;2;230;219;116;48;2;39;40;34m - Slicked-back green hair.\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[38;2;230;219;116;48;2;39;40;34m\"\"\"\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[38;2;149;144;119;48;2;39;40;34m# Based on the description, this character resembles The Joker.\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[38;2;248;248;242;48;2;39;40;34mcharacter\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;255;70;137;48;2;39;40;34m=\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34mThe Joker\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[48;2;39;40;34m \u001b[0m \n", " \u001b[38;2;248;248;242;48;2;39;40;34mfinal_answer\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m(\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m{\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34mdescription\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m:\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mdescription\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m,\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34mcharacter\u001b[0m\u001b[38;2;230;219;116;48;2;39;40;34m\"\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m:\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mcharacter\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m}\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m)\u001b[0m\u001b[48;2;39;40;34m \u001b[0m \n", " ───────────────────────────────────────────────────────────────────────────────────────────────────────────────── \n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Out - Final answer: {'description': '\\n1. Costume:\\n   - A purple suit with a yellow shirt and a large purple bow \n",
              "tie.\\n   - Features a white flower lapel and a playing card in the second image.\\n   - The style is flamboyant, \n",
              "consistent with a comic villain.\\n\\n2. Makeup:\\n   - White face makeup covering the entire face.\\n   - Red lips \n",
              "forming a wide, exaggerated smile.\\n   - Blue eyeshadow with dark eye accents.\\n   - Slicked-back green hair.\\n', \n",
              "'character': 'The Joker'}\n",
              "
\n" ], "text/plain": [ "\u001b[1;38;2;212;183;2mOut - Final answer: {'description': '\\n1. Costume:\\n - A purple suit with a yellow shirt and a large purple bow \u001b[0m\n", "\u001b[1;38;2;212;183;2mtie.\\n - Features a white flower lapel and a playing card in the second image.\\n - The style is flamboyant, \u001b[0m\n", "\u001b[1;38;2;212;183;2mconsistent with a comic villain.\\n\\n2. Makeup:\\n - White face makeup covering the entire face.\\n - Red lips \u001b[0m\n", "\u001b[1;38;2;212;183;2mforming a wide, exaggerated smile.\\n - Blue eyeshadow with dark eye accents.\\n - Slicked-back green hair.\\n', \u001b[0m\n", "\u001b[1;38;2;212;183;2m'character': 'The Joker'}\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
[Step 1: Duration 7.36 seconds| Input tokens: 7,431 | Output tokens: 302]\n",
              "
\n" ], "text/plain": [ "\u001b[2m[Step 1: Duration 7.36 seconds| Input tokens: 7,431 | Output tokens: 302]\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from smolagents import CodeAgent, OpenAIServerModel\n", "\n", "model = OpenAIServerModel(model_id=\"gpt-4o\")\n", "\n", "# Instantiate the agent\n", "agent = CodeAgent(\n", " tools=[],\n", " model=model,\n", " max_steps=20,\n", " verbosity_level=2\n", ")\n", "\n", "response = agent.run(\n", " \"\"\"\n", " Describe the costume and makeup that the comic character in these photos is wearing and return the description.\n", " Tell me if the guest is The Joker or Wonder Woman.\n", " \"\"\",\n", " images=images\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "uvKj37AmeIu0", "outputId": "ed7984d4-f6a2-4062-9939-41cb2e97b3b2" }, "outputs": [ { "data": { "text/plain": [ "{'description': '\\n1. Costume:\\n - A purple suit with a yellow shirt and a large purple bow tie.\\n - Features a white flower lapel and a playing card in the second image.\\n - The style is flamboyant, consistent with a comic villain.\\n\\n2. Makeup:\\n - White face makeup covering the entire face.\\n - Red lips forming a wide, exaggerated smile.\\n - Blue eyeshadow with dark eye accents.\\n - Slicked-back green hair.\\n',\n", " 'character': 'The Joker'}" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "response" ] }, { "cell_type": "markdown", "source": [ "In this case, the output reveals that the person is impersonating someone else, so we can prevent The Joker from entering the party!" ], "metadata": { "id": "NrV-yK5zbT9r" } }, { "cell_type": "markdown", "metadata": { "id": "ziyfk-3ZrHw5" }, "source": [ "## Providing Images with Dynamic Retrieval\n", "\n", "This examples is provided as a `.py` file since it needs to be run locally since it'll browse the web. Go to the [Hugging Face Agents Course](https://www.hf.co/learn/agents-course) for more details." ] } ], "metadata": { "colab": { "provenance": [] }, "kernelspec": { "display_name": "Python 3", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 0 }