Spaces:
Build error
Build error
File size: 629 Bytes
11a1ba7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | import gradio as gr
from transformers import pipeline
from PIL import Image
# Load the image-to-text pipeline
captioner = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
def generate_caption(image):
result = captioner(image)
return result[0]['generated_text']
# Define the Gradio interface
interface = gr.Interface(
fn=generate_caption,
inputs=gr.Image(type="pil"),
outputs=gr.Textbox(label="Caption"),
title="Image Captioning App",
description="Upload an image and get a caption using the BLIP model."
)
# Launch the app
if __name__ == "__main__":
interface.launch()
|