AI & ML

Multi-Modal AI Applications using Vision Models

By Mohd Baquir Qureshi
Code and Code Analysis

The transition from text-only Large Language Models (LLMs) to Vision-Language Models (VLMs) has unlocked an entirely new dimension of automation. Models like GPT-4o, Claude 3.5 Sonnet, and open-source alternatives like LLaVA can now understand images, screenshots, diagrams, and documents natively.

Practical Use Cases in Enterprise

In my experience building enterprise systems, vision models are highly effective for automating tasks that previously required manual data entry:

  • Automated Invoice Processing: Traditional OCR systems struggle with varying invoice layouts. A VLM can accept an image of any invoice and output structured JSON containing the vendor, date, line items, and total amount, adapting seamlessly to any format.
  • E-commerce Product Tagging: Instead of manually writing metadata, you can feed an image of a product to a VLM and have it generate comprehensive tags, color profiles, material descriptions, and alt text for SEO.
  • UI/UX Testing Agents: An AI agent can navigate a website, take screenshots, analyze the visual layout against a Figma design, and flag visual regressions or alignment issues automatically.

Implementing Vision with Python

Using the OpenAI API to analyze an image is straightforward. The key is to encode the image as a base64 string or provide a direct public URL.

import base64
import requests
from openai import OpenAI

client = OpenAI()

def encode_image(image_path):
    with open(image_path, "rb") as image_file:
        return base64.b64encode(image_file.read()).decode('utf-8')

base64_image = encode_image("product_image.jpg")

response = client.chat.completions.create(
  model="gpt-4o",
  messages=[
    {
      "role": "user",
      "content": [
        {"type": "text", "text": "Describe this product in detail for an e-commerce catalog. Format as JSON with 'title', 'description', and 'tags'."},
        {
          "type": "image_url",
          "image_url": {
            "url": f"data:image/jpeg;base64,{base64_image}",
            "detail": "high"
          }
        }
      ]
    }
  ],
  response_format={ "type": "json_object" }
)

print(response.choices[0].message.content)

Optimizing Costs and Latency

Vision models are computationally expensive. When passing images to an API, use the detail: "low" setting if you only need a general understanding of the image (e.g., identifying if it's a dog or a cat). This resizes the image and processes it with far fewer tokens.

Use detail: "high" only when the model needs to read text (OCR), analyze fine details, or evaluate UI layouts. Always crop or scale down excessively large images before encoding them in Base64 to save on payload size and API costs.