Image-to-Text
Transformers
pixeltext
feature-extraction
ocr
vision-language
paligemma
custom-model
text-extraction
document-ai
multi-language
custom_code
Instructions to use BabaK07/pixeltext-ai with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use BabaK07/pixeltext-ai with Transformers:
# Use a pipeline as a high-level helper # Warning: Pipeline type "image-to-text" is no longer supported in transformers v5. # You must load the model directly (see below) or downgrade to v4.x with: # 'pip install "transformers<5.0.0' from transformers import pipeline pipe = pipeline("image-to-text", model="BabaK07/pixeltext-ai", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("BabaK07/pixeltext-ai", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
| """ | |
| Advanced usage example for the Custom PaliGemma OCR Model. | |
| """ | |
| from transformers import AutoModel | |
| from PIL import Image | |
| import json | |
| def advanced_ocr_example(): | |
| """Advanced OCR usage with custom prompts and batch processing.""" | |
| # Load model | |
| model = AutoModel.from_pretrained("your-username/your-model-name", trust_remote_code=True) | |
| # Example 1: Custom prompt for invoice | |
| invoice_image = Image.open("invoice.jpg") | |
| invoice_result = model.generate_ocr_text( | |
| image=invoice_image, | |
| prompt="<image>Extract all text and numbers from this invoice:", | |
| max_length=1024 | |
| ) | |
| print("Invoice OCR Result:") | |
| print(f"Text: {invoice_result['text']}") | |
| print(f"Confidence: {invoice_result['confidence']:.3f}") | |
| # Example 2: Batch processing | |
| images = [ | |
| Image.open("doc1.jpg"), | |
| Image.open("doc2.jpg"), | |
| Image.open("doc3.jpg") | |
| ] | |
| batch_results = model.batch_ocr(images) | |
| print("\nBatch Processing Results:") | |
| for i, result in enumerate(batch_results): | |
| print(f"Document {i+1}: {result['text'][:50]}...") | |
| print(f"Confidence: {result['confidence']:.3f}") | |
| # Example 3: Model information | |
| info = model.get_model_info() | |
| print("\nModel Information:") | |
| print(json.dumps(info, indent=2)) | |
| return batch_results | |
| if __name__ == "__main__": | |
| advanced_ocr_example() | |