Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,19 @@
|
|
1 |
-
from transformers import pipeline
|
2 |
-
image_captioner = pipeline("image-to-text",model="Salesforce/blip-image-captioning-large")
|
3 |
-
#Set up Prerequisites for Image Captioning App User Interface
|
4 |
-
import os
|
5 |
-
import io
|
6 |
-
import IPython.display
|
7 |
from PIL import Image
|
8 |
-
import
|
9 |
-
|
10 |
import gradio as gr
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
allow_flagging="never")
|
28 |
-
|
29 |
-
ImageCaptionApp.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from PIL import Image
|
2 |
+
import requests
|
|
|
3 |
import gradio as gr
|
4 |
|
5 |
+
from transformers import BlipProcessor, BlipForConditionalGeneration
|
6 |
+
|
7 |
+
model_id = "Salesforce/blip-image-captioning-base"
|
8 |
+
|
9 |
+
model = BlipForConditionalGeneration.from_pretrained(model_id)
|
10 |
+
processor = BlipProcessor.from_pretrained(model_id)
|
11 |
+
|
12 |
+
def launch(input):
|
13 |
+
image = Image.open(requests.get(input, stream=True).raw).convert('RGB')
|
14 |
+
inputs = processor(image, return_tensors="pt")
|
15 |
+
out = model.generate(**inputs)
|
16 |
+
return processor.decode(out[0], skip_special_tokens=True)
|
17 |
+
|
18 |
+
iface = gr.Interface(launch, inputs="text", outputs="text")
|
19 |
+
iface.launch()
|
|
|
|
|
|