File size: 797 Bytes
65c5e3c | 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 27 28 29 30 31 32 33 34 35 36 37 | from transformers import BlipProcessor, BlipForConditionalGeneration
import gradio as gr
# Load processor and model
processor = BlipProcessor.from_pretrained(
"Salesforce/blip-image-captioning-base"
)
model = BlipForConditionalGeneration.from_pretrained(
"Salesforce/blip-image-captioning-base"
)
# Function
def generate_caption(image):
inputs = processor(images=image, return_tensors="pt")
output = model.generate(**inputs)
caption = processor.decode(
output[0],
skip_special_tokens=True
)
return caption
# Gradio interface
demo = gr.Interface(
fn=generate_caption,
inputs=gr.Image(type="pil"),
outputs="text",
title="AI Image Caption Generator",
description="Upload image and AI describes it."
)
# Launch app
demo.launch() |