Skip to content

Instantly share code, notes, and snippets.

@cx0
Last active April 9, 2024 21:25
Show Gist options
  • Save cx0/23b549727799fae26a86a7b4042a5dee to your computer and use it in GitHub Desktop.
Save cx0/23b549727799fae26a86a7b4042a5dee to your computer and use it in GitHub Desktop.
GPT4V turbo performance on images with rotated text
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4-turbo",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "I just bought these trash bags. Q1: What are the dimensions (in centimeter) printed on the box? Q2: Does it fit 12.5 gallon trash can?"},
{
"type": "image_url",
"image_url": {
"url": "https://gist.github.com/assets/7856061/d6af6df9-82bb-4b43-b61b-d2821aa76aae",
},
},
],
}
],
max_tokens=800,
)
print(response.choices[0])
###
# Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='The image shows a box of GLAD ForceFlex Tall Kitchen Drawstring Trash Bags (40 count) enhanced with Febreze freshness and labeled as "Hawaiian Aloha" scent. However, the dimensions of the bags are not visible on the box shown in the image.\n\nFor your first question regarding the dimensions in centimeters, typical dimensions for tall kitchen bags are approximately 61 cm wide by 74 cm long (24 in x 28.5 in). However, please check the box or a product website for the specific dimensions if they are available.\n\nFor your second question about compatibility with a 12.5 gallon trash can, since 12.5 gallons is roughly 47 liters, and the bags on the box are generally designed for tall kitchen trash bins, which typically hold 13 gallons (around 49 liters), these bags should fit a 12.5 gallon trash can comfortably.', role='assistant', function_call=None, tool_calls=None)
### ```
@cx0
Copy link
Author

cx0 commented Apr 9, 2024

trashbag

@cx0
Copy link
Author

cx0 commented Apr 9, 2024

# %%
import base64
from anthropic import Anthropic
from IPython.display import Image

client = Anthropic(api_key=api_key)
MODEL_NAME = "claude-3-opus-20240229"

def get_base64_encoded_image(image_path):
    with open(image_path, "rb") as image_file:
        binary_data = image_file.read()
        base_64_encoded_data = base64.b64encode(binary_data)
        base64_string = base_64_encoded_data.decode('utf-8')
        return base64_string

# %%
# Image(filename='trashbag.jpg') 


# %%
message_list = [
    {
        "role": 'user',
        "content": [
            {"type": "image", "source": {"type": "base64", "media_type": "image/jpeg", "data": get_base64_encoded_image("trashbag.jpg")}},
            {"type": "text", "text": "I just bought these trash bags. Q1: What are the dimensions (in centimeter) printed on the box? Q2: Does it fit 12.5 gallon trash can?"}
        ]
    }
]

response = client.messages.create(
    model=MODEL_NAME,
    max_tokens=4096,
    messages=message_list
)
print(response.content[0].text)

# %%

###
# According to the image, the Glad ForceFlex trash bag box indicates the dimensions are "40.6 cm x 48.3 cm" (15 x 19 inches).
#
# Regarding your second question, 40.6 cm x 48.3 cm corresponds to approximately 10 gallons in volume. The product is labeled as "Tall Kitchen" bags, which are typically designed for smaller kitchen trash cans, not large 12-13 gallon bins. So while you might be able to fit the bag over a 12.5 gallon can, it would likely be an extremely snug fit without much overhang, making it difficult to secure and remove the filled bag. For a 12.5 gallon trash can, I would recommend looking for bags specifically marketed as fitting that larger size to ensure proper fit and ease of use.
###

@cx0
Copy link
Author

cx0 commented Apr 9, 2024

Gemini 1.5 Pro

gemini_1 5pro

@cx0
Copy link
Author

cx0 commented Apr 9, 2024

Reka Flash

reka_flash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment