A Python library for working with vision models.
Project description
limin-vision
A Python library for working with vision models.
Installation
Install the library using pip:
pip install limin-vision
A Simple Example
After you've installed the library, you can use it by importing the limin_vision module and calling the functions you need.
You will need to provide the OPENAI_API_KEY environment variable.
Now, you can create a simple script to process an image from a URL:
import asyncio
from limin_vision import process_image_from_url
async def main():
url = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"
result = await process_image_from_url(url)
print(result)
if __name__ == "__main__":
asyncio.run(main())
Side Note: Passing the API Key
The limin-vision library gives you two ways to provide the API key.
The simplest one is to simply set the OPENAI_API_KEY environment variable by running export OPENAI_API_KEY=$YOUR_API_KEY.
You can also create a .env file in the root directory of your project and add the following line:
OPENAI_API_KEY=$YOUR_API_KEY
Note that you will need to load the .env file in your project using a library like python-dotenv:
import dotenv
dotenv.load_dotenv()
Processing an Image
You can pass additional parameters to the process_image_from_url function to customize the model configuration and prompt:
await process_image_from_url(
url,
prompt="What's in this image?",
model_configuration=ModelConfiguration(
model="gpt-4o",
temperature=1.0
),
detail="high",
)
You can find the full example in examples/process_from_url.py.
Alternatively, you can process an image from a local file by calling process_image_from_file instead of process_image_from_url.
from limin_vision import process_image_from_file
async def main():
result = await process_image_from_file("image.png")
print(result)
if __name__ == "__main__":
asyncio.run(main())
Just like with process_image_from_url, you can pass additional parameters to the process_image_from_file function to customize the model configuration and prompt:
await process_image_from_file(
"image.png",
prompt="What's in this image?",
model_configuration=ModelConfiguration(
model="gpt-4o",
temperature=1.0
),
detail="high",
)
You can find the full example in examples/process_from_file.py.
You can also get a structured response from the model by passing a response model to the process_image_from_url_structured or process_image_from_file_structured functions.
For example, here's how you can process an image from a URL and get a structured response:
import asyncio
from limin_vision import process_image_from_url_structured
from pydantic import BaseModel
class ImageResponse(BaseModel):
title: str
description: str
async def main():
url = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"
result = await process_image_from_url_structured(url, ImageResponse)
print(result)
if __name__ == "__main__":
asyncio.run(main())
You can find the full example in examples/process_from_url_structured.py.
You can also process an image from a local file by calling process_image_from_file_structured instead of process_image_from_file.
from limin_vision import process_image_from_file_structured
async def main():
result = await process_image_from_file_structured("image.png", ImageResponse)
print(result)
if __name__ == "__main__":
asyncio.run(main())
You can find the full example in examples/process_from_file_structured.py.
Image Generation
You can generate an image from a text prompt by calling the generate_image_to_bytes or generate_image_to_file functions.
For example, here's how you can generate an image from a text prompt and save it to a file:
from limin_vision import generate_image_to_file
async def main():
await generate_image_to_file(
"A beautiful sunset over a calm ocean",
"output.png",
)
You can find the full example in examples/image_generation_to_file.py.
You can also generate an image from a text prompt and get the image as bytes by calling generate_image_to_bytes:
from limin_vision import generate_image_to_bytes
async def main():
image_generation_completion = await generate_image_to_bytes(
"A beautiful sunset over a calm ocean",
)
image_bytes = image_generation_completion.content
print(image_bytes)
if __name__ == "__main__":
asyncio.run(main())
You can find the full example in examples/image_generation_to_bytes.py.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file limin_vision-0.3.0.tar.gz.
File metadata
- Download URL: limin_vision-0.3.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e3094e281f166581e073feee8e79a10282cd0dacc56a9a3fea46e0d260c2308
|
|
| MD5 |
2901ce823a0e1ee354708f51cfb4e70e
|
|
| BLAKE2b-256 |
ec9668d660265c3f2e96d275b788509c4f2ab39d120f299eede272df4c817ca8
|
File details
Details for the file limin_vision-0.3.0-py3-none-any.whl.
File metadata
- Download URL: limin_vision-0.3.0-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a0cc671ed945873617548b2c92cb6e2e81424f71f83ae997e0faf9ba4608024c
|
|
| MD5 |
6f90440b976eb5d8a16814413bb42492
|
|
| BLAKE2b-256 |
76ff12c2eabbc48212a5c60fe50e51fe133de0f3cdf947f1017f33146933db70
|