Spaces:
Runtime error
Runtime error
from PIL import Image | |
import gradio as gr | |
from transformers import BlipProcessor, BlipForConditionalGeneration | |
model_id = "Salesforce/blip-image-captioning-base" | |
model = BlipForConditionalGeneration.from_pretrained(model_id) | |
processor = BlipProcessor.from_pretrained(model_id) | |
def launch(input_image): | |
# Convert Gradio image input to PIL Image | |
image = Image.fromarray(input_image) | |
# Process the image and generate a caption | |
inputs = processor(image, return_tensors="pt") | |
out = model.generate(**inputs) | |
caption = processor.decode(out[0], skip_special_tokens=True) | |
return caption | |
iface = gr.Interface( | |
launch, | |
inputs=gr.inputs.Image(type="pil"), # Set input type to image | |
outputs="text" | |
) | |
iface.launch() | |