Reality123b commited on
Commit
a6047f6
·
verified ·
1 Parent(s): 9ec25bb

Create image_captioning.py

Browse files
application/utils/image_captioning.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+
3
+ class ImageCaptioning:
4
+ def __init__(self):
5
+ self.captioner = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large")
6
+
7
+ def generate_caption(self, image_data):
8
+ try:
9
+ caption = self.captioner(image_data)[0]['generated_text']
10
+ return caption
11
+ except Exception as e:
12
+ print(f"Error during image captioning: {e}")
13
+ return "Error processing image."