Spaces:
Build error
Build error
| 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() | |