Skip to main content

Get descriptions of images from OpenAI, Azure OpenAI, and Anthropic Claude models in an easy way.

Project description

TextFromImage

Python Version PyPI Version License Downloads

A powerful Python library for obtaining detailed descriptions of images using various AI models including OpenAI's GPT models, Azure OpenAI, and Anthropic Claude. Perfect for applications requiring image understanding, accessibility features, and content analysis.

🌟 Key Features

  • 🤖 Multiple AI Providers: Support for OpenAI, Azure OpenAI, and Anthropic Claude
  • 🔄 Flexible Integration: Easy-to-use API with multiple initialization options
  • 🎯 Custom Prompting: Configurable prompts for targeted descriptions
  • 🔑 Secure Authentication: Multiple authentication methods including environment variables
  • 🛠️ Model Selection: Support for different model versions and configurations
  • 📝 Type Hints: Full typing support for better development experience

📦 Installation

pip install textfromimage

🚀 Quick Start

OpenAI Integration

import textfromimage

# Initialize with API key
textfromimage.openai.init(api_key="your-openai-api-key")

# Get image description
image_url = 'https://example.com/image.jpg'
description = textfromimage.openai.get_description(image_url=image_url)
print(f"Description: {description}")

💡 Advanced Usage

🤖 Multiple Provider Support

# Anthropic Claude Integration
textfromimage.claude.init(api_key="your-anthropic-api-key")
claude_description = textfromimage.claude.get_description(image_url=image_url)

# Azure OpenAI Integration
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"
)
azure_description = textfromimage.azure_openai.get_description(image_url=image_url)

🔧 Configuration Options

# Environment Variable Configuration
import os
os.environ['OPENAI_API_KEY'] = 'your-openai-api-key'
os.environ['ANTHROPIC_API_KEY'] = 'your-anthropic-api-key'
os.environ['AZURE_OPENAI_API_KEY'] = 'your-azure-openai-api-key'
os.environ['AZURE_OPENAI_ENDPOINT'] = 'your-azure-endpoint'
os.environ['AZURE_OPENAI_DEPLOYMENT'] = 'your-deployment-name'

# Custom Model Selection
description = textfromimage.openai.get_description(
    image_url=image_url,
    model='gpt-4o-mini'
)

# Custom Prompting
description = textfromimage.openai.get_description(
    image_url=image_url,
    prompt="Describe the main elements and composition of this image"
)

📋 Parameters

@dataclass
class DescriptionParams:
    image_url: str
    prompt: str = "What's in this image?"
    model: str = "gpt-4o"
    api_key: Optional[str] = None

🔍 Error Handling

from textfromimage.exceptions import APIKeyError, InvalidImageError, ModelError

try:
    description = textfromimage.openai.get_description(image_url=image_url)
except APIKeyError as e:
    print(f"API key error: {e}")
except InvalidImageError as e:
    print(f"Image error: {e}")
except ModelError as e:
    print(f"Model error: {e}")

🤝 Contributing

We welcome contributions! Here's how you can help:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

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

textfromimage-1.0.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

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

textfromimage-1.0.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file textfromimage-1.0.0.tar.gz.

File metadata

  • Download URL: textfromimage-1.0.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for textfromimage-1.0.0.tar.gz
Algorithm Hash digest
SHA256 505b4cca5e0dd521687c5d245c7f4cef80aef8fa0bee4d9912354f61ec9d1f68
MD5 9c3847725555a41e37fa0f7ddfe78a10
BLAKE2b-256 7fa937b39df073ebd617d7e459ead102c15684d1aec20f7ef4924ac8c2753acc

See more details on using hashes here.

File details

Details for the file textfromimage-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: textfromimage-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for textfromimage-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 53bef30453c6a357811fe86cfa70b0e6008893f08c8e917e1971031f368f2b7c
MD5 decf2a89822eaeb0faa6cf832edc7aa9
BLAKE2b-256 e9a1e0436c29da70e6e3f9bc455bcb16030ce18a3050f44abeecd312e7ce12f6

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