Tagging media with Langchain
If you're working with images you can use the multimodal LLMs supported by Langchain.
Prerequisites
- A concrete Langchain library installed and configured
Supported media
- IMAGE
Installation
pip install media-tagging-langchain
uv pip install media-tagging-langchain
If you want to use server capabilities of media-tagger
you need to install additional dependencies:
pip install media-tagging[server]
Usage
media-tagger tag MEDIA_PATHs \
--media-type IMAGE \
--tagger langchain \
--tagger.llm_class_name=<FULLY_QUALIFIED_CLASS_NAME>
Where
<FULLY_QUALIFIED_CLASS_NAME>
- fully path to the LLM class (i.e.langchain_google_genai.ChatGoogleGenerativeAI
). Corresponding library should be installed before calling themedia-tagger
.
import media_tagging
media_tagger = media_tagging.MediaTaggingService()
request = media_tagging.MediaTaggingRequest(
media_type='IMAGE',
media_paths=['image1.png', 'image2.png'],
tagger_type='langchain',
tagging_options={
'llm_class_name': 'langchain_google_genai.ChatGoogleGenerativeAI',
}
)
result = media_tagger.tag_media(request)
result.save(output='tagging_results', writer='csv')
curl -X 'POST' \
'http://127.0.0.1:8000/media_tagging/tag' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"tagger_type": "langchain",
"media_type": "IMAGE",
"media_paths": [
"image1.png",
"image2.png"
],
"tagging_options": {
"llm_class_name": "langchain_google_genai.ChatGoogleGenerativeAI"
}
}'