Tagging media with Langchain
If you're working with images & texts you can use the multimodal LLMs supported by Langchain.
Prerequisites
- A concrete Langchain library installed and configured
Supported media
- TEXT
- 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/api/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"
}
}'
Customization
Depending on selected LLM you may pass additional parameters to configure it.
For example, for ChatOllama you can
setup over 20 parameters
of your choice such as base_url, temperature, reasoning, etc.
model
media-tagger tag MEDIA_PATHs \
--media-type IMAGE \
--tagger langchain \
--tagger.llm_class_name=<FULLY_QUALIFIED_CLASS_NAME> \
--tagger.model=MODEL_NAME
Where
MODEL_NAME- name of the models supported by a concrete LLM (i.e.gemma4:e2bsupported bylangchain_ollama.ChatOllama).
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_ollama.ChatOllama',
'model': 'gemma4:e2b',
}
)
result = media_tagger.tag_media(request)
result.save(output='tagging_results', writer='csv')
curl -X 'POST' \
'http://127.0.0.1:8000/api/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",
"model": "gemma4:e2b"
}
}'