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:
- Moondream Cloud: (with 5,000 free requests/day): get a free API key from the Moondream cloud console.
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file moondream-0.1.0.tar.gz
.
File metadata
- Download URL: moondream-0.1.0.tar.gz
- Upload date:
- Size: 96.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.9 Darwin/24.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2501731a8a9aae5183049ef6c0619b89dfadcc3b665141e64a0f3548173284b0 |
|
MD5 | b24079d5ef99e933a76e8923c342efd8 |
|
BLAKE2b-256 | e5f7136d98a7424564a689c92734407022e980ca5b3084c180c82de650c07a78 |
File details
Details for the file moondream-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: moondream-0.1.0-py3-none-any.whl
- Upload date:
- Size: 94.6 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | d04611e6df73615f6cf8f042699dcd0079d2dd95d5abf67a1b4daaf4e95bfdc7 |
|
MD5 | c6a216b37453f272a32a3f1acbda4126 |
|
BLAKE2b-256 | 7e1fd57aacd700c559dd82d820a1c96fefaf15d5b046083a97b026c47bc08448 |