SaiBrahmam
commited on
Commit
·
f369493
1
Parent(s):
f1efdfc
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
from PIL import Image
|
3 |
+
from transformers import BlipProcessor, BlipForConditionalGeneration
|
4 |
+
|
5 |
+
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
6 |
+
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base").to("cuda")
|
7 |
+
|
8 |
+
img_url = 'https://www.chitramala.in/wp-content/gallery/pawan-kalyan-pspk25-movie-working-stills/PSPK-25-Movie-Location-Photos-5.jpg'
|
9 |
+
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
|
10 |
+
|
11 |
+
# conditional image captioning
|
12 |
+
text = "a photography of"
|
13 |
+
inputs = processor(raw_image, text, return_tensors="pt").to("cuda")
|
14 |
+
|
15 |
+
out = model.generate(**inputs)
|
16 |
+
print(processor.decode(out[0], skip_special_tokens=True))
|
17 |
+
# >>> a photography of a woman and her dog
|
18 |
+
|
19 |
+
# unconditional image captioning
|
20 |
+
inputs = processor(raw_image, return_tensors="pt").to("cuda")
|
21 |
+
|
22 |
+
out = model.generate(**inputs)
|
23 |
+
print(processor.decode(out[0], skip_special_tokens=True))
|