Spaces:
Runtime error
Runtime error
Update app.py
Browse files123456789import gradio as grdef greet(name, intensity):return "Hello, " + name + "!" * int(intensity)demo = gr.Interface(fn=greet,inputs=["text", "slider"],outputs=["text"],)demo.launch()123456789101112131415161718192021222324252627282930313233import gradio as grfrom transformers import BlipProcessor, BlipForConditionalGenerationfrom PIL import Imageprocessor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")def generate_caption(image):# Now directly using the PIL Image objectinputs = processor(images=image, return_tensors="pt")outputs = model.generate(**inputs)caption = processor.decode(outputs[0], skip_special_tokens=True)return captiondef caption_image(image):"""Takes a PIL Image input and returns a caption."""try:caption = generate_caption(image)return captionexcept Exception as e:return f"An error occurred: {str(e)}"iface = gr.Interface(fn=caption_image,inputs=gr.Image(type="pil"),outputs="text",title="Image Captioning with BLIP",description="Upload an image to generate a caption.")iface.launch()
app.py+31-7