Spaces:
Build error
Build error
Download src/models/imageCaptioning.py from Chinar-Q-AI/Image2Story: direct link, hf CLI and curl.
- Browser
- Download file 518 Bytes
-
https://huggingface.co/spaces/Chinar-Q-AI/Image2Story/resolve/refs%2Fpr%2F3/src/models/imageCaptioning.py
- Command line
-
hf download hf://spaces/Chinar-Q-AI/Image2Story@refs/pr/3/src/models/imageCaptioning.py
-
curl -L -o imageCaptioning.py https://huggingface.co/spaces/Chinar-Q-AI/Image2Story/resolve/refs%2Fpr%2F3/src/models/imageCaptioning.py
518 Bytes
| from PIL import Image | |
| from transformers import BlipProcessor , BlipForConditionalGeneration | |
| import torch | |
| processor = BlipProcessor.from_pretrained("src/models/Caption") | |
| model = BlipForConditionalGeneration.from_pretrained("src/models/Caption") | |
| def generateCaption(image_path): | |
| image = Image.open(image_path).convert("RGB") | |
| inputs = processor(images = image , return_tensors="pt") | |
| output = model.generate(**inputs) | |
| caption = processor.decode(output[0], skip_special_tokens = True) | |
| return caption |