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