Spaces:
Runtime error
Runtime error
Create ap.py
Browse files
ap.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from PIL import Image
|
3 |
+
from transformers.utils import logging
|
4 |
+
from transformers import BlipForConditionalGeneration, AutoProcessor
|
5 |
+
|
6 |
+
logging.set_verbosity_error()
|
7 |
+
|
8 |
+
model = BlipForConditionalGeneration.from_pretrained("./models/Salesforce/blip-image-captioning-base")
|
9 |
+
processor = AutoProcessor.from_pretrained("./models/Salesforce/blip-image-captioning-base")
|
10 |
+
|
11 |
+
def caption_image(image):
|
12 |
+
inputs = processor(image, return_tensors="pt")
|
13 |
+
out = model.generate(**inputs)
|
14 |
+
caption = processor.decode(out[0], skip_special_tokens=True)
|
15 |
+
return caption
|
16 |
+
|
17 |
+
image_input = gr.inputs.Image()
|
18 |
+
caption_output = gr.outputs.Textbox()
|
19 |
+
|
20 |
+
gr.Interface(caption_image, image_input, caption_output).launch()
|