Skip to main content

Python client library for moondream

Project description

Moondream Python Client Library

Python client library for moondream. This library is an alpha preview -- it is in an early stage of development, and backward compatibility is not yet guaranteed. If you are using this in production, please pin the revision you are using.

This library currently offers optimized CPU inference, but will be slower than the PyTorch implementation for CUDA and MPS backends. If you are running on a Mac with M1/M2/M3 etc. chips, or if you have a GPU available, this library is not recommended yet.

Setup

Install the library using pip:

pip install moondream==0.0.1

Then download the model weights:

# int8 weights (recommended):
wget "https://huggingface.co/vikhyatk/moondream2/resolve/client/moondream-latest-int8.bin.gz?download=true" -O - | gunzip > moondream-latest-int8.bin
# ...or, for FP16 weights:
wget "https://huggingface.co/vikhyatk/moondream2/resolve/client/moondream-latest-f16.bin.gz?download=true" -O - | gunzip > moondream-latest-f16.bin

Usage

import moondream as md
from PIL import Image

model = md.VL("moondream-latest-int8.bin")
image = Image.open("path/to/image.jpg")

# Optional -- encode the image to efficiently run multiple queries on the same
# image. This is not mandatory, since the model will automatically encode the
# image if it is not already encoded.
encoded_image = model.encode_image(image)

# Caption the image.
caption = model.caption(encoded_image)

# ...or, if you want to stream the output:
for t in model.caption(encoded_image, stream=True)["caption"]:
    print(t, end="", flush=True)

# Ask a question about the image.
question = "How many people are in this image?"
answer = model.answer_question(encoded_image, question)["answer"]

# ...or again, if you want to stream the output:
for t in model.answer_question(encoded_image, question, stream=True)["answer"]:
    print(t, end="", flush=True)

Accelerators

(TK -- document how ONNX execution providers work.)

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.0.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

moondream-0.0.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: moondream-0.0.1.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.4 Darwin/23.5.0

File hashes

Hashes for moondream-0.0.1.tar.gz
Algorithm Hash digest
SHA256 bfdecf25f27551ebbd6db1a6fea2a8f903902b52cb7ff9719946e3305abcabec
MD5 793d72c4397dec32af618412b43290f0
BLAKE2b-256 f175bd6d16e8db96792aa3e40517bccc81e4fd3f930aac73f2a3e13f416f7138

See more details on using hashes here.

File details

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

File metadata

  • Download URL: moondream-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.4 Darwin/23.5.0

File hashes

Hashes for moondream-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e3bdcb66bf6b5f494dc8e66bd7fbca50234f24de30054a16418456920c34ad44
MD5 1547e8e77b9acd073f649d1efa18fe74
BLAKE2b-256 aa2b3663e3a582519dc2c67a1bfd9105ee039c4387abb6912a7432556b3629b8

See more details on using hashes here.

Supported by

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