Spaces:
Sleeping
Sleeping
Commit ·
21d2426
1
Parent(s): 75a2655
initial commit
Browse files- .gitignore +1 -0
- app.py +26 -0
- requirements.txt +4 -0
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
venv/
|
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import BlipProcessor, BlipForConditionalGeneration
|
| 3 |
+
from PIL import Image
|
| 4 |
+
|
| 5 |
+
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
| 6 |
+
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
|
| 7 |
+
|
| 8 |
+
def generate_caption(image):
|
| 9 |
+
if image is None:
|
| 10 |
+
return "Please upload an image to generate a caption."
|
| 11 |
+
inputs = processor(images=image, return_tensors="pt")
|
| 12 |
+
out = model.generate(**inputs)
|
| 13 |
+
caption = processor.decode(out[0], skip_special_tokens=True)
|
| 14 |
+
return caption
|
| 15 |
+
|
| 16 |
+
iface = gr.Interface(
|
| 17 |
+
fn=generate_caption,
|
| 18 |
+
inputs=gr.Image(type="pil", label="Upload Image"),
|
| 19 |
+
outputs="text",
|
| 20 |
+
live=True,
|
| 21 |
+
title="Image Captioning App",
|
| 22 |
+
description="Upload an image and get a description of what the image contains.",
|
| 23 |
+
allow_flagging="never"
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
iface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
transformers
|
| 3 |
+
torch
|
| 4 |
+
Pillow
|