Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,21 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
def greet(img):
|
| 7 |
return caption(img)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
from PIL import Image
|
| 4 |
+
from transformers import BlipProcessor, BlipForConditionalGeneration
|
| 5 |
|
| 6 |
+
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-large")
|
| 7 |
+
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large")
|
| 8 |
+
|
| 9 |
+
img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
|
| 10 |
+
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
|
| 11 |
+
|
| 12 |
+
def caption(img):
|
| 13 |
+
raw_image = Image.open(img).convert('RGB')
|
| 14 |
+
|
| 15 |
+
inputs = processor(raw_image, return_tensors="pt")
|
| 16 |
+
|
| 17 |
+
out = model.generate(**inputs, min_length=30, max_length=1000)
|
| 18 |
+
return processor.decode(out[0], skip_special_tokens=True)
|
| 19 |
|
| 20 |
def greet(img):
|
| 21 |
return caption(img)
|