Spaces:
Sleeping
Sleeping
| # app.py | |
| from transformers import pipeline | |
| import gradio as gr | |
| # Load the image captioning pipeline | |
| pipe = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base") | |
| # Define the function that gets the caption | |
| def caption_image(image): | |
| result = pipe(image) | |
| return result[0]["generated_text"] | |
| # Build the Gradio interface | |
| interface = gr.Interface( | |
| fn=caption_image, | |
| inputs=gr.Image(type="pil"), | |
| outputs="text", | |
| title="🖼️ BLIP Image Captioning", | |
| description="Upload an image and get a caption using Salesforce's BLIP image captioning model." | |
| ) | |
| # Launch the app | |
| if __name__ == "__main__": | |
| interface.launch() | |