File size: 468 Bytes
a6047f6
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
from transformers import pipeline

class ImageCaptioning:
    def __init__(self):
        self.captioner = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large")

    def generate_caption(self, image_data):
        try:
            caption = self.captioner(image_data)[0]['generated_text']
            return caption
        except Exception as e:
            print(f"Error during image captioning: {e}")
            return "Error processing image."