|
from transformers import pipeline
|
|
|
|
def load_image_model():
|
|
"""
|
|
Loads HuggingFaceTB/SmolVLM-500M-Instruct or another image-to-text model.
|
|
"""
|
|
return pipeline("image-to-text", model="HuggingFaceTB/SmolVLM-500M-Instruct")
|
|
|
|
def analyze_image(image_file, image_model):
|
|
"""
|
|
Pass an image file to the image model pipeline and return the text/caption.
|
|
"""
|
|
result = image_model(image_file)
|
|
if isinstance(result, list) and len(result) > 0:
|
|
return result[0].get("generated_text", "No caption generated.")
|
|
return "Unable to process image."
|
|
|