Spaces:
Sleeping
Sleeping
File size: 922 Bytes
11143e5 768f8e0 11143e5 768f8e0 11143e5 768f8e0 11143e5 768f8e0 11143e5 | 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 | import gradio as gr
from transformers import BlipProcessor, BlipForConditionalGeneration
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
def generate_caption(image):
if image is None:
return "Please upload an image."
image = image.convert("RGB")
inputs = processor(image, return_tensors="pt")
output = model.generate(**inputs, max_new_tokens=50)
caption = processor.decode(output[0], skip_special_tokens=True)
return caption
demo = gr.Interface(
fn=generate_caption,
inputs=gr.Image(type="pil", label="Upload an Image"),
outputs=gr.Textbox(label="Generated Caption"),
title="AI Image Captioning App",
description="Upload an image and generate a caption using the BLIP image captioning model."
)
demo.launch() |