File size: 661 Bytes
41b63a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
26
# 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()