Skip to content

Commit

Permalink
move things around, remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
mertyg committed Jul 8, 2024
1 parent e23503b commit ab405f6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 61 deletions.
65 changes: 4 additions & 61 deletions examples/notebooks/TextGrad-Vision-MathVista.ipynb
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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"
]
},
{
Expand All @@ -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"
]
},
Expand All @@ -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\""
]
},
{
Expand All @@ -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)"
]
},
Expand Down Expand Up @@ -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",
Expand Down
File renamed without changes

0 comments on commit ab405f6

Please sign in to comment.