From ab405f68a9f935f2df752adb8d70a7486aefe189 Mon Sep 17 00:00:00 2001 From: mertyg Date: Sun, 7 Jul 2024 18:51:10 -0700 Subject: [PATCH] move things around, remove unused code --- .../notebooks/TextGrad-Vision-MathVista.ipynb | 65 ++---------------- .../{mathvista => notebooks/assets}/176.png | Bin 2 files changed, 4 insertions(+), 61 deletions(-) rename examples/{mathvista => notebooks/assets}/176.png (100%) diff --git a/examples/notebooks/TextGrad-Vision-MathVista.ipynb b/examples/notebooks/TextGrad-Vision-MathVista.ipynb index abcbf92..cba0942 100644 --- a/examples/notebooks/TextGrad-Vision-MathVista.ipynb +++ b/examples/notebooks/TextGrad-Vision-MathVista.ipynb @@ -1,30 +1,5 @@ { "cells": [ - { - "cell_type": "code", - "execution_count": 20, - "id": "6e5bfa16-5124-452c-bc56-3427e453751a", - "metadata": { - "vscode": { - "languageId": "shellscript" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "The autoreload extension is already loaded. To reload it, use:\n", - " %reload_ext autoreload\n" - ] - } - ], - "source": [ - "%load_ext autoreload\n", - "\n", - "%autoreload 2" - ] - }, { "cell_type": "code", "execution_count": 21, @@ -39,28 +14,7 @@ "# Some utils to read images\n", "\n", "import io\n", - "from PIL import Image\n", - "\n", - "def encode_image(image):\n", - " # Convert RGBA to RGB if necessary\n", - " if image.mode == 'RGBA':\n", - " # Create a new image with a white background\n", - " background = Image.new('RGB', image.size, (255, 255, 255))\n", - " # Paste the image on the background.\n", - " background.paste(image, (0, 0), image)\n", - " image = background\n", - "\n", - " # Create a BytesIO object\n", - " buffered = io.BytesIO()\n", - "\n", - " # Save your image object to this BytesIO object (in JPEG format)\n", - " image.save(buffered, format=\"JPEG\")\n", - "\n", - " # Get the byte data from the BytesIO object\n", - " image_byte_data = buffered.getvalue()\n", - "\n", - " # Encode this byte data in base64 and return the string\n", - " return image_byte_data" + "from PIL import Image" ] }, { @@ -76,8 +30,7 @@ "source": [ "import textgrad as tg\n", "from textgrad import get_engine\n", - "from textgrad.utils.image_utils import download_and_cache_image\n", - "from textgrad.autograd import OrderedFieldsMultimodalLLMCall, MultimodalLLMCall\n", + "from textgrad.autograd import MultimodalLLMCall\n", "from textgrad.loss import ImageQALoss" ] }, @@ -96,10 +49,7 @@ "\n", "# Assuming the OpenAI API key is stored in an environment variable named 'OPENAI_API_KEY'\n", "openai_api_key = os.getenv('OPENAI_API_KEY')\n", - "assert openai_api_key is not None and len(openai_api_key) > 0, \"Please set the OPENAI_API_KEY environment variable\"\n", - "\n", - "# Print the OpenAI API key\n", - "# print(openai_api_key)" + "assert openai_api_key is not None and len(openai_api_key) > 0, \"Please set the OPENAI_API_KEY environment variable\"" ] }, { @@ -113,13 +63,6 @@ }, "outputs": [], "source": [ - "from dotenv import load_dotenv\n", - "load_dotenv(override=True)\n", - "\n", - "# Claude Model\n", - "# tg.set_backward_engine(\"claude-3-haiku-20240307\", override=True)\n", - "\n", - "# GP4-o Model\n", "tg.set_backward_engine(\"gpt-4o\", override=True)" ] }, @@ -159,7 +102,7 @@ "import httpx\n", "\n", "# Path to the local image\n", - "image_path = \"../mathvista/176.png\"\n", + "image_path = \".assets/176.png\"\n", "\n", "# Read the local image file in binary mode\n", "with open(image_path, 'rb') as file:\n", diff --git a/examples/mathvista/176.png b/examples/notebooks/assets/176.png similarity index 100% rename from examples/mathvista/176.png rename to examples/notebooks/assets/176.png