A module to generate captions for images using Google AI's Vertex AI Platform.
Project description
ImageTextCaptions
A Python module to generate captions for images using Google AI's Vertex AI Platform.
Overview
The ImageTextCaptions class provides an intuitive interface for generating textual captions for images. By simply passing a base64 encoded image, users can get insightful and accurate captions for their visual content.
Features
- Easy integration with Google AI's Vertex AI Platform.
- Support for custom Google Cloud Project IDs.
- Flexibility to use either a Google Cloud credentials file or rely on
gcloud auth. - Option to set a custom base URL for the API endpoint.
Installation
Ensure you have the required libraries:
pip install requests google-auth
Usage
Convert Image to Base64:
import base64
def convert_image_to_base64(image_path):
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode('utf-8')
Generate Captions:
from imagetext_captions import ImageTextCaptions
# Convert your image to base64
b64_image = convert_image_to_base64("path_to_your_image.jpg")
# Instantiate with your Google Cloud Project ID
captions = ImageTextCaptions("YOUR_PROJECT_ID")
# Define the number of responses you want and the language code
response_count = 1
language_code = "en"
# Generate captions
response = captions.caption(b64_image, response_count, language_code)
# Print the captions from the response
for caption in response["predictions"]:
print(caption)
Using a Google Cloud Credentials File:
captions = ImageTextCaptions("YOUR_PROJECT_ID", credentials_path="path_to_your_google_cloud_credentials.json")
Specifying a Custom Base URL:
custom_url = "https://your_custom_base_url/v1/projects/{project_id}/locations/some_location/publishers/google/models/imagetext:predict"
captions = ImageTextCaptions("YOUR_PROJECT_ID", base_url=custom_url)
Contributions
Contributions are welcome! If you find any issues or have suggestions for improvements, please submit a pull request or open an issue.
License
This project is licensed under the MIT License.
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 ImageTextCaptions-0.1.0.tar.gz.
File metadata
- Download URL: ImageTextCaptions-0.1.0.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4fda8e0f1b219eb338260e814655a10c695a1ac565061980400d4179b5da998
|
|
| MD5 |
acbd13f8a705eaa40349375cd93e09b3
|
|
| BLAKE2b-256 |
0a6479f19dd7b565e064637708cd3a985ef0a30094204ee458a5fb3f6b999147
|
File details
Details for the file ImageTextCaptions-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ImageTextCaptions-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b436af4909f106cb5b7612d3b674761a314b96c3b68ac14cbb25f296ea3c1348
|
|
| MD5 |
c23dfc170ccffc63bb5a7efbb1ced6a0
|
|
| BLAKE2b-256 |
7c203099a3c513d5cc2a96813c6456f466d499f9239ae963a738a01757e1d437
|