caption.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from transformers import BlipProcessor, BlipForConditionalGeneration
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
| 7 |
+
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
|
| 8 |
+
|
| 9 |
+
def caption_image(image):
|
| 10 |
+
inputs = processor(images=image, return_tensors="pt")
|
| 11 |
+
out = model.generate(**inputs)
|
| 12 |
+
caption = processor.decode(out[0], skip_special_tokens=True)
|
| 13 |
+
return caption
|
| 14 |
+
|
| 15 |
+
gr.Interface(fn=caption_image, inputs=gr.Image(), outputs="text").launch()
|