Spaces:
Runtime error
Runtime error
Commit
·
84f9b87
1
Parent(s):
2dc45c3
Upload folder using huggingface_hub
Browse files- README.md +2 -8
- app.py +26 -0
- example_1.jpg +0 -0
- example_2.jpg +0 -0
- example_3.jpg +0 -0
- requirements.txt +1 -0
README.md
CHANGED
|
@@ -1,12 +1,6 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
|
| 4 |
-
colorFrom: yellow
|
| 5 |
-
colorTo: pink
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 3.44.1
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
---
|
| 11 |
-
|
| 12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Image_Captioning
|
| 3 |
+
app_file: app.py
|
|
|
|
|
|
|
| 4 |
sdk: gradio
|
| 5 |
sdk_version: 3.44.1
|
|
|
|
|
|
|
| 6 |
---
|
|
|
|
|
|
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
from lavis.models import load_model_and_preprocess
|
| 6 |
+
|
| 7 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 8 |
+
|
| 9 |
+
model, vis_processors, _ = load_model_and_preprocess(
|
| 10 |
+
name="blip_caption", model_type="large_coco", is_eval=True, device=device
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
def predict(image):
|
| 14 |
+
pre_processed_image = vis_processors["eval"](image).unsqueeze(0).to(device)
|
| 15 |
+
response = model.generate({"image": pre_processed_image}, use_nucleus_sampling=True, num_captions=3)
|
| 16 |
+
return image, ",\n".join(response)
|
| 17 |
+
|
| 18 |
+
demo = gr.Interface(
|
| 19 |
+
title="Image Captioning - BLIP",
|
| 20 |
+
fn=predict,
|
| 21 |
+
inputs=gr.Image(type='pil', label="Original Image"),
|
| 22 |
+
outputs=[gr.Image(type="pil"), gr.Textbox()],
|
| 23 |
+
examples=["example_1.jpg", "example_2.jpg"],
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
demo.launch()
|
example_1.jpg
ADDED
|
example_2.jpg
ADDED
|
example_3.jpg
ADDED
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
salesforce-lavis
|