Spaces:
Sleeping
Sleeping
Upload 5 files
Browse files- Sea.jpg +0 -0
- Umbrella.jpg +0 -0
- app.py +30 -0
- bridge.jpg +0 -0
- requirements.txt +3 -0
Sea.jpg
ADDED
![]() |
Umbrella.jpg
ADDED
![]() |
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import io
|
3 |
+
import IPython.display
|
4 |
+
from PIL import Image
|
5 |
+
from transformers import pipeline
|
6 |
+
import gradio as gr
|
7 |
+
|
8 |
+
hf_api_key = os.environ["HF_API_KEY"]
|
9 |
+
|
10 |
+
get_completion = pipeline(os.environ["TASK"],model= os.environ["MODEL"])
|
11 |
+
|
12 |
+
def summarize(input):
|
13 |
+
output = get_completion(input)
|
14 |
+
return output[0]['generated_text']
|
15 |
+
|
16 |
+
def captioner(image):
|
17 |
+
result = get_completion(image)
|
18 |
+
return result[0]['generated_text']
|
19 |
+
|
20 |
+
gr.close_all()
|
21 |
+
demo = gr.Interface(fn=captioner,
|
22 |
+
inputs=[gr.Image(label="Upload image", type="pil")],
|
23 |
+
outputs=[gr.Textbox(label="Caption")],
|
24 |
+
title="Image Captioning with BLIP",
|
25 |
+
description="Caption any image using the BLIP model",
|
26 |
+
allow_flagging="never",
|
27 |
+
examples=["bridge.jpg", "Sea.jpg", "Umbrella.jpg"])
|
28 |
+
|
29 |
+
|
30 |
+
demo.launch(share=True)
|
bridge.jpg
ADDED
![]() |
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
IPython
|
2 |
+
transformers
|
3 |
+
gradio
|