Skip to main content

Python client library for moondream

Project description

Moondream Python Client Library

Official Python client library for Moondream, a fast multi-function VLM. This client can target either the Moondream Cloud or a Moondream Server. Both are free, though the cloud has a limits on the free tier.

Capabilities

Moondream goes beyond the typical VLM "query" ability to include more visual functions. These include:

  • caption: Generate descriptive captions for images
  • query: Ask questions about image content
  • detect: Find bounding boxes around objects in images
  • point: Identify the center location of specified objects in images

You can try this out anytime on Moondream's playground.

Installation

Install the package from PyPI:

pip install moondream

Quick Start

Choose how you want to run it:

  1. Moondream Cloud: (with 5,000 free requests/day): get a free API key from the Moondream cloud console.
  2. Moondream Server: Run it locally by installing and running the Moondream server.

Once you've done at least one of these, try running this code:

import moondream as md
from PIL import Image

# Initialize for Moondream Cloud
model = md.vl(api_key="<your-api-key>")

# ...or initialize for a local Moondream Server
model = md.vl(endpoint="http://localhost:2020/v1")

# Load an image
image = Image.open("path/to/image.jpg")

# Generate a caption
caption = model.caption(image)["caption"]
print("Caption:", caption)

# Ask a question
answer = model.query(image, "What's in this image?")["answer"]
print("Answer:", answer)

# Stream the response
for chunk in model.caption(image, stream=True)["caption"]:
    print(chunk, end="", flush=True)

API Reference

Constructor

# Cloud inference
model = md.vl(api_key="<your-api-key>")

# Local inference
model = md.vl(endpoint="http://localhost:2020/v1")

Methods

caption(self, image: Union[Image.Image, EncodedImage], length: Literal["normal", "short", "long"] = "normal", stream: bool = False) -> CaptionOutput

Generate a caption for an image.

caption = model.caption(image, length="short")["caption"]
print(caption)

# Generate a caption with streaming (default: False)
for chunk in model.caption(image, length="short", stream=True)["caption"]:
    print(chunk, end="", flush=True)

query(self, image: Union[Image.Image, EncodedImage], question: str, stream: bool = False) -> QueryOutput

Ask a question about an image.

answer = model.query(image, question="What's in this image?")["answer"]
print("Answer:", answer)

# Ask a question with streaming (default: False)
for chunk in model.query(image, question="What's in this image?", stream=True)["answer"]:
    print(chunk, end="", flush=True)

detect(self, image: Union[Image.Image, EncodedImage], object: str) -> DetectOutput

Detect specific objects in an image.

detect_output = model.detect(image, "item")["objects"]
print(detect_output)

point(self, image: Union[Image.Image, EncodedImage], object: str) -> PointOutput

Get coordinates of specific objects in an image.

point_output = model.point(image, "person")
print(point_output)

encode_image(self, image: Union[Image.Image, EncodedImage]) -> Base64EncodedImage

Produce Base64EncodedImage.

encoded_image = model.encode_image(image)

Image Types

  • Image.Image: PIL Image object
  • Base64EncodedImage: Object produced by model.encode_image(image), subtype of EncodedImage

Response Types

  • CaptionOutput: {"caption": str | Generator}
  • QueryOutput: {"answer": str | Generator}
  • DetectOutput: {"objects": List[Region]}
  • PointOutput: {"points": List[Point]}
  • Region: Bounding box with coordinates (x_min, y_min, x_max, y_max)
  • Point: Coordinates (x, y) indicating the object center

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

moondream-0.1.1.tar.gz (96.3 kB view details)

Uploaded Source

Built Distribution

moondream-0.1.1-py3-none-any.whl (94.9 kB view details)

Uploaded Python 3

File details

Details for the file moondream-0.1.1.tar.gz.

File metadata

  • Download URL: moondream-0.1.1.tar.gz
  • Upload date:
  • Size: 96.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.9 Darwin/24.3.0

File hashes

Hashes for moondream-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6da586f030eceaf8e74f8c5d8a84fe3db9dc5f6f8d5c2011db08837afef9f1f8
MD5 0958ca3dae3efaa4b3da3f66b988e3ad
BLAKE2b-256 97e4921c236172c1b8505a04889a579fc6843b331ad61c5e5a3d6772c83117ef

See more details on using hashes here.

File details

Details for the file moondream-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: moondream-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 94.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.9 Darwin/24.3.0

File hashes

Hashes for moondream-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d60b60b1689eead8bc0925456ff497f1dbff2118db7c7c28343f0467c284914a
MD5 3a5947fdd17a0b8ed2804d9db521299f
BLAKE2b-256 176bc9de9fdff76b2067eaedc627c2b7644512d0b432e2e32b0b883cf1d71354

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page