Commit
·
1e2ba49
1
Parent(s):
a2851d4
Update app.py
Browse files
app.py
CHANGED
@@ -3,18 +3,13 @@ from transformers import AutoProcessor, Blip2ForConditionalGeneration
|
|
3 |
import torch
|
4 |
from PIL import Image
|
5 |
|
|
|
|
|
|
|
6 |
# Load the BLIP-2 model and processor
|
7 |
-
# Load the BLIP-2 model and processor without int8 quantization
|
8 |
processor = AutoProcessor.from_pretrained("Salesforce/blip2-opt-2.7b")
|
9 |
model = Blip2ForConditionalGeneration.from_pretrained("Salesforce/blip2-opt-2.7b").to(device)
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
# Set device to GPU if available
|
16 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
17 |
-
|
18 |
def blip2_interface(image, prompted_caption_text, vqa_question, chat_context):
|
19 |
# Prepare image input
|
20 |
image_input = Image.fromarray(image).convert('RGB')
|
|
|
3 |
import torch
|
4 |
from PIL import Image
|
5 |
|
6 |
+
# Set device to GPU if available
|
7 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
8 |
+
|
9 |
# Load the BLIP-2 model and processor
|
|
|
10 |
processor = AutoProcessor.from_pretrained("Salesforce/blip2-opt-2.7b")
|
11 |
model = Blip2ForConditionalGeneration.from_pretrained("Salesforce/blip2-opt-2.7b").to(device)
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
def blip2_interface(image, prompted_caption_text, vqa_question, chat_context):
|
14 |
# Prepare image input
|
15 |
image_input = Image.fromarray(image).convert('RGB')
|