import gradio as gr import requests from PIL import Image from transformers import BlipProcessor, BlipForConditionalGeneration processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base") model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base") def caption_image(raw_image): inputs = processor(raw_image, return_tensors="pt") out = model.generate(**inputs) return processor.decode(out[0], skip_special_tokens=True) outputs = [ gr.outputs.Textbox(label="Caption, including detected generator (if applicable)"), ] demo = gr.Interface(fn=caption_image, inputs="image", outputs=outputs) demo.launch()