Skip to main content
Glama

zero_shot_image_classification

Classify images using custom labels without prior training. Upload an image and specify categories to identify objects, scenes, or content using AI-powered computer vision.

Instructions

Classify an image with zero-shot labels using DeepInfra OpenAI-compatible API (CLIP).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
candidate_labelsYes
image_urlYes
modelNo

Implementation Reference

  • The core handler function for the 'zero_shot_image_classification' tool. It is decorated with @app.tool() for automatic MCP registration and implements the logic using an OpenAI-compatible vision model to classify the image against provided candidate labels, returning a JSON-formatted result or error.
    @app.tool() async def zero_shot_image_classification(image_url: str, candidate_labels: list[str]) -> str: """Classify an image with zero-shot labels using DeepInfra OpenAI-compatible API (CLIP).""" model = DEFAULT_MODELS["zero_shot_image_classification"] try: # Use chat/completions with vision capability to get classification response = await client.chat.completions.create( model=model, messages=[ { "role": "user", "content": [ { "type": "text", "text": f"Classify this image into one of these categories: {', '.join(candidate_labels)}. Return a JSON with 'label' and 'score' fields." }, { "type": "image_url", "image_url": {"url": image_url} } ] } ], max_tokens=200, ) if response.choices: return response.choices[0].message.content else: return "Unable to classify image" except Exception as e: return f"Error classifying image: {type(e).__name__}: {str(e)}"
  • Conditional registration logic that defines the tool only if enabled via ENABLED_TOOLS environment variable or 'all'.
    if "all" in ENABLED_TOOLS or "zero_shot_image_classification" in ENABLED_TOOLS:
  • Default model configuration for the zero_shot_image_classification tool, retrievable via environment variable.
    "zero_shot_image_classification": os.getenv("MODEL_ZERO_SHOT_IMAGE_CLASSIFICATION", "openai/gpt-4o-mini"),

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/phuihock/mcp-deeinfra'

If you have feedback or need assistance with the MCP directory API, please join our Discord server