Spaces:
Runtime error
Runtime error
Commit
·
791c833
1
Parent(s):
10b0641
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
image_url = "https://free-images.com/sm/9596/dog_animal_greyhound_983023.jpg"
|
5 |
+
get_completion = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
6 |
+
|
7 |
+
def summarize(input):
|
8 |
+
output = get_completion(input)
|
9 |
+
return output[0]['generated_text']
|
10 |
+
|
11 |
+
|
12 |
+
import gradio as gr
|
13 |
+
|
14 |
+
def captioner(image):
|
15 |
+
result = get_completion(image)
|
16 |
+
return result[0]['generated_text']
|
17 |
+
|
18 |
+
gr.close_all()
|
19 |
+
demo = gr.Interface(fn=captioner,
|
20 |
+
inputs=[gr.Image(label="Upload image", type="pil")],
|
21 |
+
outputs=[gr.Textbox(label="Caption")],
|
22 |
+
title="Image Captioning with BLIP",
|
23 |
+
description="Caption any image using the BLIP model",
|
24 |
+
allow_flagging="never")
|
25 |
+
demo.launch()
|
26 |
+
|