image-caption2 / app.py
a7madmostafa's picture
Create app.py
49a9578 verified
Raw History Blame Contribute Delete
609 Bytes
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()