Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,21 +2,34 @@ import gradio as gr
|
|
2 |
# from PIL import Image
|
3 |
from transformers.utils import logging
|
4 |
from transformers import BlipForConditionalGeneration, AutoProcessor
|
|
|
5 |
|
6 |
-
|
|
|
7 |
|
8 |
-
|
9 |
-
|
|
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
return caption
|
16 |
|
|
|
17 |
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
# gr.Interface(caption_image, gr.inputs.Image(), "text").launch()
|
21 |
# gr.Interface(caption_image, image_input, caption_output).launch()
|
22 |
|
|
|
2 |
# from PIL import Image
|
3 |
from transformers.utils import logging
|
4 |
from transformers import BlipForConditionalGeneration, AutoProcessor
|
5 |
+
from transformers import pipeline
|
6 |
|
7 |
+
pipe = pipeline("image-to-text",
|
8 |
+
model="./models/Salesforce/blip-image-captioning-base")
|
9 |
|
10 |
+
def launch(input):
|
11 |
+
out = pipe(input)
|
12 |
+
return out[0]['generated_text']
|
13 |
|
14 |
+
iface = gr.Interface(launch,
|
15 |
+
inputs=gr.Image(type='pil'),
|
16 |
+
outputs="text")
|
17 |
+
iface.launch()
|
|
|
18 |
|
19 |
+
# logging.set_verbosity_error()
|
20 |
|
21 |
+
# model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
|
22 |
+
# processor = AutoProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
23 |
+
|
24 |
+
# def caption_image(image):
|
25 |
+
# inputs = processor(image, return_tensors="pt")
|
26 |
+
# out = model.generate(**inputs)
|
27 |
+
# caption = processor.decode(out[0], skip_special_tokens=True)
|
28 |
+
# return caption
|
29 |
+
|
30 |
+
|
31 |
+
# iface = gr.Interface(fn=caption_image, inputs=["image"], outputs="textbox")
|
32 |
+
# iface.launch()
|
33 |
# gr.Interface(caption_image, gr.inputs.Image(), "text").launch()
|
34 |
# gr.Interface(caption_image, image_input, caption_output).launch()
|
35 |
|