Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -116,11 +116,13 @@ processor = BlipProcessor.from_pretrained("Salesforce/blip-vqa-base")
|
|
| 116 |
model = BlipForQuestionAnswering.from_pretrained("Salesforce/blip-vqa-base").to("cuda" if torch.cuda.is_available() else "cpu")
|
| 117 |
|
| 118 |
# Function
|
| 119 |
-
def vqa_answer(
|
| 120 |
-
image
|
| 121 |
-
inputs =
|
| 122 |
-
out =
|
| 123 |
-
|
|
|
|
|
|
|
| 124 |
|
| 125 |
# Example
|
| 126 |
# print(vqa_answer("baby.jpg", "What is the baby eating?"))
|
|
|
|
| 116 |
model = BlipForQuestionAnswering.from_pretrained("Salesforce/blip-vqa-base").to("cuda" if torch.cuda.is_available() else "cpu")
|
| 117 |
|
| 118 |
# Function
|
| 119 |
+
def vqa_answer(image, question):
|
| 120 |
+
# image is already a PIL Image (no need to open again)
|
| 121 |
+
inputs = vqa_processor(image, question, return_tensors="pt").to(vqa_model.device)
|
| 122 |
+
out = vqa_model.generate(**inputs, max_new_tokens=50)
|
| 123 |
+
answer = vqa_processor.decode(out[0], skip_special_tokens=True)
|
| 124 |
+
return answer
|
| 125 |
+
|
| 126 |
|
| 127 |
# Example
|
| 128 |
# print(vqa_answer("baby.jpg", "What is the baby eating?"))
|