Get descriptions of images from OpenAI, Azure OpenAI, and Anthropic Claude models in an easy way.
Project description
TextFromImage
Get descriptions of images using OpenAI's GPT models, Azure OpenAI, and Anthropic Claude in an easy way.
Installation
You can install the textfromimage package via PyPI using pip:
pip install textfromimage
Usage
The textfromimage package is now class-based, allowing you to initialize the TextFromImage class with your desired configurations and use its methods to obtain image descriptions.
Using OpenAI
import textfromimage
# Option 1: Initialize OpenAI client with API key
textfromimage.openai.init(api_key="your-openai-api-key")
# Option 2: Set your OpenAI API key as an environment variable
# import os
# os.environ['OPENAI_API_KEY'] = 'your-openai-api-key'
# Get a description of the image using OpenAI
image_url = 'https://example.com/image.jpg'
openai_description = textfromimage.openai.get_description(
image_url=image_url"
)
print("OpenAI Description:", openai_description)
Using Anthropic Claude
import textfromimage
# Option 1: Initialize Anthropic Claude client with API key
textfromimage.claude.init(api_key="your-anthropic-api-key")
# Option 2: Set your Anthropic API key as an environment variable
# import os
# os.environ['ANTHROPIC_API_KEY'] = 'your-anthropic-api-key'
# Get a description of the image using Anthropic Claude
image_url = 'https://example.com/image.jpg'
claude_description = textfromimage.claude.get_description(
image_url=image_url"
)
print("Claude Description:", claude_description)
Using Azure OpenAI
import textfromimage
# Option 1: Initialize Azure OpenAI client with necessary parameters
textfromimage.azure_openai.init(
api_key="your-azure-openai-api-key",
api_base="https://your-azure-endpoint.openai.azure.com/",
deployment_name="your-deployment-name"
)
# Option 2: Set your Azure OpenAI credentials as environment variables
# import os
# os.environ['AZURE_OPENAI_API_KEY'] = 'your-azure-openai-api-key'
# os.environ['AZURE_OPENAI_ENDPOINT'] = 'https://your-azure-endpoint.openai.azure.com/'
# os.environ['AZURE_OPENAI_DEPLOYMENT'] = 'your-deployment-name'
# Get a description of the image using Azure OpenAI
image_url = 'https://example.com/image.jpg'
azure_description = textfromimage.azure_openai.get_description(
image_url=image_url"
)
print("Azure OpenAI Description:", azure_description)
Specifying a Different Model
You can specify a different OpenAI model if needed. By default, the model is set to "gpt-4o".
import textfromimage
# Option 1: Initialize OpenAI client with API key
textfromimage.openai.init(api_key="your-openai-api-key")
# Option 2: Set your OpenAI API key as an environment variable
# import os
# os.environ['OPENAI_API_KEY'] = 'your-openai-api-key'
# Get a description of the image using OpenAI
image_url = 'https://example.com/image.jpg'
openai_description = textfromimage.openai.get_description(
image_url=image_url,
model='gpt-4o-mini'"
)
print("OpenAI Description:", openai_description)
Parameters
- image_url (str): The URL of the image.
- prompt (str, optional): The prompt for the description (default: "What's in this image?").
- model (str, optional): The OpenAI model to use (default: "gpt-4o").
- api_key (str, optional): Your OpenAI API key.
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch (git checkout -b feature/YourFeature).
- Commit your changes (git commit -m 'Add some feature').
- Push to the branch (git push origin feature/YourFeature).
- Open a pull request.
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
Built Distribution
File details
Details for the file textfromimage-0.3.1.tar.gz
.
File metadata
- Download URL: textfromimage-0.3.1.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc9eba3593cda4bbc50c6f8eda96edacde492791fa6da777b004cea91ccbdbf3 |
|
MD5 | 26a99ced97a85cd5f9b4d7fbf8b0c406 |
|
BLAKE2b-256 | d86f691ca522825e36a28f0ca18db17d668d02f8ae8c3a32c8d6cefeb2db46c0 |
File details
Details for the file textfromimage-0.3.1-py3-none-any.whl
.
File metadata
- Download URL: textfromimage-0.3.1-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 700f5b11c1fc260849747b3eb4db99e18d557f78189b9d86f78716068e733c46 |
|
MD5 | 051988669285d83db7b59b0f26194d59 |
|
BLAKE2b-256 | 6dede768fe638dd410e4e6ac553f4a62323770117ed96ef82fe453976bcfe6ad |