Spaces:
Sleeping
Sleeping
Commit
·
9c5499b
1
Parent(s):
f8bccee
Add application file
Browse files- app.py +29 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import io
|
3 |
+
import IPython.display
|
4 |
+
from PIL import Image
|
5 |
+
import base64
|
6 |
+
from transformers import pipeline
|
7 |
+
import gradio as gr
|
8 |
+
|
9 |
+
import warnings
|
10 |
+
warnings.filterwarnings("ignore")
|
11 |
+
|
12 |
+
task = "image-to-text"
|
13 |
+
model = "Salesforce/blip-image-captioning-base"
|
14 |
+
image_captioner = pipeline("image-to-text", model = "Salesforce/blip-image-captioning-base")
|
15 |
+
|
16 |
+
def captioner(image):
|
17 |
+
result = image_captioner(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 |
+
)
|
28 |
+
|
29 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio==3.39.0
|
2 |
+
transformers==4.24.0
|
3 |
+
torch
|