Spaces:
Running
Running
Commit
·
6ac2f26
1
Parent(s):
d192bd3
req changed
Browse files
model.py
CHANGED
|
@@ -1,14 +1,13 @@
|
|
| 1 |
import torch
|
| 2 |
-
from transformers import
|
| 3 |
from PIL import Image
|
| 4 |
|
| 5 |
# Load BLIP-2 model and processor
|
| 6 |
-
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 11 |
-
|
| 12 |
def generate_answer(image: Image.Image, question: str) -> str:
|
| 13 |
if not image.mode == "RGB":
|
| 14 |
image = image.convert("RGB")
|
|
|
|
| 1 |
import torch
|
| 2 |
+
from transformers import AutoProcessor, AutoModelForVisualQuestionAnswering
|
| 3 |
from PIL import Image
|
| 4 |
|
| 5 |
# Load BLIP-2 model and processor
|
| 6 |
+
# Load model directly
|
| 7 |
+
processor = AutoProcessor.from_pretrained("Salesforce/blip2-flan-t5-xl")
|
| 8 |
+
model = AutoModelForVisualQuestionAnswering.from_pretrained("Salesforce/blip2-flan-t5-xl")
|
| 9 |
|
| 10 |
|
|
|
|
|
|
|
| 11 |
def generate_answer(image: Image.Image, question: str) -> str:
|
| 12 |
if not image.mode == "RGB":
|
| 13 |
image = image.convert("RGB")
|