Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from transformers import AutoProcessor | |
| from transformers import BlipForConditionalGeneration | |
| model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base") | |
| processor = AutoProcessor.from_pretrained("Salesforce/blip-image-captioning-base") | |
| def caption_image(image): | |
| inputs = processor(image, return_tensors="pt") | |
| output = model.generate(**inputs) | |
| caption = processor.decode(output[0], skip_special_tokens=True) | |
| return caption | |
| img_captioning_interface = gr.Interface( | |
| fn=caption_image, | |
| inputs=gr.Image(label="Input Image", type="pil"), | |
| outputs=gr.Textbox(label="Predicted Caption"), | |
| title="Image Caption Generator App", | |
| description="This app generates a caption for an image.", | |
| examples=["./examples/image1.jpg"] | |
| ) |