Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from PIL import Image
|
| 4 |
+
pipe = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large")
|
| 5 |
+
def generate_caption(image):
|
| 6 |
+
# Generate a caption for the image
|
| 7 |
+
captions = pipe(image)
|
| 8 |
+
return captions[0]['generated_text']
|
| 9 |
+
demo = gr.Interface(
|
| 10 |
+
fn=generate_caption,
|
| 11 |
+
inputs=gr.Image(type="pil", label="Upload an Image"),
|
| 12 |
+
outputs=gr.Textbox(label="Generated Caption"),
|
| 13 |
+
title="Image Caption Generator",
|
| 14 |
+
description="Upload an image to generate a caption using the BLIP model."
|
| 15 |
+
)
|
| 16 |
+
if __name__ == "__main__":
|
| 17 |
+
demo.launch(share=True)
|