Spaces:
Sleeping
Sleeping
File size: 609 Bytes
49a9578 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | import gradio as gr
from transformers import pipeline
pipe = pipeline(
"image-to-text",
model="Salesforce/blip-image-captioning-base"
)
def caption_image(image):
if image is None:
return "Please upload an image."
result = pipe(image)
return result[0]["generated_text"]
demo = gr.Interface(
fn=caption_image,
inputs=gr.Image(type="pil", label="Upload Image"),
outputs=gr.Textbox(label="Generated Caption"),
title="Image Captioning App",
description="Upload an image and the BLIP model will generate a caption."
)
if __name__ == "__main__":
demo.launch() |