To use BLIP-2 for visual question answering task, the textual prompt has to follow a specific format: Question: {} Answer:.

prompt = f"Question: {question} Answer:" 

Now we need to preprocess the image/prompt with the model's processor, pass the processed input through the model, and decode the output: