joyson commited on
Commit
0eaa2ae
Β·
verified Β·
1 Parent(s): c857caa

Delete image_to_text.py

Browse files
Files changed (1) hide show
  1. image_to_text.py +0 -31
image_to_text.py DELETED
@@ -1,31 +0,0 @@
1
- from transformers import BlipProcessor, BlipForConditionalGeneration
2
- from PIL import Image
3
- import spaces
4
-
5
- @spaces.GPU
6
- class ImageToText:
7
- """
8
- Class to handle Image-to-Text captioning using BLIP.
9
- """
10
- def __init__(self):
11
- # Initialize the processor and model
12
- print("Loading Image-to-Text model...")
13
- self.processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-large")
14
- self.model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large")
15
- print("Image-to-Text model loaded successfully.")
16
-
17
-
18
- async def generate_caption(self, image):
19
- """
20
- Generate a descriptive caption for an uploaded image.
21
-
22
- Args:
23
- image (PIL.Image): The image to caption.
24
-
25
- Returns:
26
- str: The generated caption.
27
- """
28
- inputs = self.processor(image, return_tensors="pt")
29
- out = self.model.generate(**inputs)
30
- caption = self.processor.decode(out[0], skip_special_tokens=True)
31
- return caption