Update README.md
Browse files
README.md
CHANGED
|
@@ -6,3 +6,22 @@ languages:
|
|
| 6 |
- en
|
| 7 |
license: bsd-3-clause
|
| 8 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
- en
|
| 7 |
license: bsd-3-clause
|
| 8 |
---
|
| 9 |
+
|
| 10 |
+
```python
|
| 11 |
+
import requests
|
| 12 |
+
from PIL import Image
|
| 13 |
+
from transformers import BlipProcessor, BlipForConditionalGeneration
|
| 14 |
+
processor = BlipProcessor.from_pretrained(""Revrse/icon-captioning-model"")
|
| 15 |
+
model = BlipForConditionalGeneration.from_pretrained(""Revrse/icon-captioning-model"")
|
| 16 |
+
img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
|
| 17 |
+
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
|
| 18 |
+
# conditional image captioning
|
| 19 |
+
text = "a photography of"
|
| 20 |
+
inputs = processor(raw_image, text, return_tensors="pt")
|
| 21 |
+
out = model.generate(**inputs)
|
| 22 |
+
print(processor.decode(out[0], skip_special_tokens=True))
|
| 23 |
+
# unconditional image captioning
|
| 24 |
+
inputs = processor(raw_image, return_tensors="pt")
|
| 25 |
+
out = model.generate(**inputs)
|
| 26 |
+
print(processor.decode(out[0], skip_special_tokens=True))
|
| 27 |
+
```
|