Spaces:
Sleeping
Sleeping
add blip feature and correct torch install
Browse files- app.py +19 -4
- requirements.txt +1 -1
app.py
CHANGED
@@ -1,7 +1,22 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import BlipProcessor, BlipForConditionalGeneration
|
3 |
|
4 |
+
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
5 |
+
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
|
6 |
|
7 |
+
def get_completion(raw_image):
|
8 |
+
|
9 |
+
inputs = processor(raw_image, return_tensors="pt")
|
10 |
+
out = model.generate(**inputs)
|
11 |
+
|
12 |
+
return processor.decode(out[0], skip_special_tokens=True)
|
13 |
+
|
14 |
+
demo = gr.Interface(fn=get_completion,
|
15 |
+
inputs=[gr.Image(label="Upload image", type="pil")],
|
16 |
+
outputs=[gr.Textbox(label="Caption")],
|
17 |
+
title="Image Captioning with BLIP",
|
18 |
+
description="Caption any image using the BLIP model",
|
19 |
+
allow_flagging="never",
|
20 |
+
examples=["https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg", "https://free-images.com/sm/9596/dog_animal_greyhound_983023.jpg"])
|
21 |
+
|
22 |
+
demo.launch()
|
requirements.txt
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
-
transformer[
|
2 |
gradio
|
|
|
1 |
+
transformer[torch]
|
2 |
gradio
|