Spaces:
Sleeping
Sleeping
| 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() |