Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,22 @@
|
|
1 |
-
import
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
|
6 |
-
def
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
return
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 generate_caption(image):
|
9 |
+
inputs = processor(image, return_tensors="pt")
|
10 |
+
outputs = model.generate(**inputs)
|
11 |
+
caption = processor.decode(outputs[0], skip_special_tokens=True)
|
12 |
+
return caption
|
13 |
|
14 |
+
interface = gr.Interface(
|
15 |
+
fn=generate_caption,
|
16 |
+
inputs=gr.Image(type="pil"),
|
17 |
+
outputs="text",
|
18 |
+
title="Image-to-Text Captioning",
|
19 |
+
description="Upload an image to generate a caption!"
|
20 |
+
)
|
21 |
+
|
22 |
+
interface.launch()
|