llama-index multi_modal_llms HuggingFace integration by [Cihan Yalçın](https://www.linkedin.com/in/chanyalcin/)
Project description
LlamaIndex Multi_Modal_Llms Integration: Huggingface
This project integrates Hugging Face's multimodal language models into the LlamaIndex framework, enabling advanced multimodal capabilities for various AI applications.
Features
- Seamless integration of Hugging Face multimodal models with LlamaIndex
- Support for multiple state-of-the-art vision-language models and their finetunes:
- Easy-to-use interface for multimodal tasks like image captioning and visual question answering
- Configurable model parameters for fine-tuned performance
Author of that Integration GitHub | LinkedIn | Email
Installation
pip install llama-index-multi-modal-llms-huggingface
Make sure to set your Hugging Face API token as an environment variable:
export HF_TOKEN=your_huggingface_token_here
Usage
Here's a basic example of how to use the Hugging Face multimodal integration:
from llama_index.multi_modal_llms.huggingface import HuggingFaceMultiModal
from llama_index.core.schema import ImageDocument
# Initialize the model
model = HuggingFaceMultiModal.from_model_name("Qwen/Qwen2-VL-2B-Instruct")
# Prepare your image and prompt
image_document = ImageDocument(image_path="path/to/your/image.jpg")
prompt = "Describe this image in detail."
# Generate a response
response = model.complete(prompt, image_documents=[image_document])
print(response.text)
Streaming
from llama_index.multi_modal_llms.huggingface import HuggingFaceMultiModal
from llama_index.core.schema import ImageDocument
# Initialize the model
model = HuggingFaceMultiModal.from_model_name("Qwen/Qwen2-VL-2B-Instruct")
# Prepare your image and prompt
image_document = ImageDocument(image_path="downloaded_image.jpg")
prompt = "Describe this image in detail."
import nest_asyncio
import asyncio
nest_asyncio.apply()
async def stream_output():
for chunk in model.stream_complete(
prompt, image_documents=[image_document]
):
print(chunk.delta, end="", flush=True)
await asyncio.sleep(0)
asyncio.run(stream_output())
You can also refer to this Colab notebook
Supported Models
- Qwen2 Vision
- Florence2
- Phi3.5 Vision
- PaliGemma
- Mllama
Each model has its unique capabilities and can be selected based on your specific use case.
Configuration
You can configure various parameters when initializing a model:
model = HuggingFaceMultiModal(
model_name="Qwen/Qwen2-VL-2B-Instruct",
device="cuda", # or "cpu"
torch_dtype=torch.float16,
max_new_tokens=100,
temperature=0.7,
)
Limitations
- Async streaming is not supported for any of the models.
- Some models have specific requirements or limitations. Please refer to the individual model classes for details.
Author of that Integration GitHub | LinkedIn | Email
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 llama_index_multi_modal_llms_huggingface-0.2.1.tar.gz
.
File metadata
- Download URL: llama_index_multi_modal_llms_huggingface-0.2.1.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92917e32da2ca2505c96205f1d44969cac3504e9f9ae14428d566ace33287d70 |
|
MD5 | 94065e50c7178d594ccc4b6d46c414e6 |
|
BLAKE2b-256 | a6435ac0c72493c7ebf051b4a4bc3605ebab8f46f27ea22ac14c39b91df889c1 |
File details
Details for the file llama_index_multi_modal_llms_huggingface-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: llama_index_multi_modal_llms_huggingface-0.2.1-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c63595906e61991a5e44b9ed2a033cbc307cc92cce9b371e62627d18599cbfb2 |
|
MD5 | 258e067e5e72b7a9dcaac82fb74cb111 |
|
BLAKE2b-256 | 1563a864d78610fd80354c4733a5429f6515c89dc7a0a40030cd58e2831b8f9c |